Pagini recente » Cod sursa (job #803151) | Cod sursa (job #2809514) | Cod sursa (job #2342789) | Cod sursa (job #2222205) | Cod sursa (job #2582195)
using namespace std;
#include<bits/stdc++.h>
ifstream fin("ordine.in");
ofstream fout("ordine.out");
struct Key
{
int freq;
char ch;
bool operator<(const Key &k) const
{
return ch > k.ch;
}
};
string str;
int n;
int fr[27];
priority_queue< Key > pq;
int main() {
fin >> str;
n = str.size();
for (int i = 0; i<str.size(); i++) {
fr[str[i] - 'a']++;
}
for (char i = 'a'; i<='z'; i++) {
if (fr[i - 'a'] > 0) {
pq.push(Key {fr[i - 'a'], i});
}
}
str = "";
Key prev = {-1, '#'};
while (!pq.empty()) {
Key k = pq.top();
pq.pop();
str += k.ch;
if (prev.freq > 0) {
pq.push(prev);
}
k.freq--;
prev = k;
}
fout << str;
fin.close();
fout.close();
return 0;
}