Cod sursa(job #918773)

Utilizator apopeid13Apopeid Alejandro apopeid13 Data 19 martie 2013 09:33:13
Problema Ordine Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <cstdio>
#include <cstring>
#define Lmax 1000001
#define alfa 26
char S[Lmax];
int f[alfa];
int main() {
freopen("ordine.in", "r", stdin);
freopen("ordine.out","w",stdout);
scanf("%s", S);
int L = strlen(S);
for (int i=0; i<L; ++i)
++f[S[i]-'a'];
int last = -1;
for (int i=0; i<L; ++i) {
int j;
for (j=0; j<26; ++j)
if (f[j] == (L-i)/2+1) {
printf("%c", j+'a');
last = j;
--f[j];
break;
}
if (j<26) continue;
for (j=0; j<26; ++j)
if (f[j] && j!=last) {
last = j;
printf("%c", j+'a');
--f[j];
break;
}
}
return 0;
}