Pagini recente » Diferente pentru problema/cuvinte intre reviziile 7 si 8 | Cod sursa (job #2710546) | Cod sursa (job #1872496) | Cod sursa (job #1454202) | Cod sursa (job #2766688)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ordine.in");
ofstream fout("ordine.out");
int main() {
string s;
fin >> s;
int n = s.size(), f[26] = {0};
for (char c : s)
++f[c - 'a'];
int last = -1;
for (int rep = 0; rep < n; ++rep) {
int best = -1;
for (int c = 0; c < 26; ++c)
if (c != last && f[c]) {
best = c;
break;
}
fout << char('a' + best);
--f[best];
last = best;
}
fout << '\n';
fin.close();
fout.close();
return 0;
}