跳到正文

题解

P14357优先队列版

yu20105约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年9月5日
收录
2026年9月5日
更新
2026年11月16日
篇幅
约 1 分钟
题目
P14357

版本

  1. v1当前

优先队列实现

用贪心的话找起来比较麻烦,如果用大根堆来实现比较简单

C++
#include<bits/stdc++.h>
using namespace std;

string s;
priority_queue<int>pq;
int main()
{
	cin>>s;
	for(char c:s)
	{
		if(c>='0'&&c<='9')
		{
			pq.push(c-'0');
		}
	}
	while(!pq.empty())
	{
		cout<<pq.top();
		pq.pop();
	}
}
原文