Pagini recente » Cod sursa (job #1014363) | Cod sursa (job #1217313) | Cod sursa (job #2680604) | Cod sursa (job #1829760) | Cod sursa (job #2766689)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ordine.in");
ofstream fout("ordine.out");
void max_self(int &x, int y) {
if (x < y)
x = y;
}
int main() {
string s;
fin >> s;
int n = s.size(), f[26] = {0}, most_freq = 0, ch = -1;
for (char c : s)
if (++f[c - 'a'] > n / 2)
ch = c;
int last = -1;
for (int rep = 0; rep < n; ++rep) {
if (rep % 2 == 0 && ch >= 0) {
fout << char('a' + ch);
last = ch;
continue;
}
int best = -1;
for (int c = 0; c < 26; ++c)
if (c != last && f[c] > 0) {
best = c;
break;
}
fout << char('a' + best);
--f[best];
last = best;
}
fout << '\n';
fin.close();
fout.close();
return 0;
}