Cod sursa(job #114287)
Utilizator | Data | 13 decembrie 2007 18:05:44 | |
---|---|---|---|
Problema | Ordine | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.75 kb |
#include <stdio.h>
#include <string.h>
char ch[1000004];
long f[28],i,j,l,last;
bool ok;
int main(){
freopen("ordine.in","r",stdin);
freopen("ordine.out","w",stdout);
scanf("%s",ch);
l=strlen(ch);
for (i=0;i<l;i++)
f[ch[i]-'a']++;
last=26;
for (i=0;i<l;i++){
ok=0;
for (j=0;j<26;j++)
if (f[j]==(l-i)/2+1){
printf("%c",'a'+j);
last=j;
f[j]--;
ok=1;
break;
}
if (!ok){
j=0;
while (!f[j]||j==last)j++;
printf("%c",'a'+j);
last=j;
f[j]--;
}
}
printf("\n");
return 0;
}