Pagini recente » Cod sursa (job #2558581) | Cod sursa (job #3259834) | Cod sursa (job #741273) | Cod sursa (job #1068954) | Cod sursa (job #533241)
Cod sursa(job #533241)
# include <stdio.h>
# include <string>
using namespace std;
# define FIN "ordine.in"
# define FOUT "ordine.out"
# define MAXN 1000010
char word[MAXN];
int letter[80];
int i,lenght;
char currentLetter,previous,following;
int main() {
freopen(FIN,"r",stdin);
freopen(FOUT,"w",stdout);
scanf("%s",word+1);
lenght = strlen(word+1);
for (i = 1; i <= lenght; ++i)
letter[word[i]]++;
previous = ' ';
for (i = 1; i <= lenght; ++i) {
following = 'z';
for (currentLetter = 'a'; currentLetter <= 'z'; ++currentLetter)
if (letter[currentLetter]==(lenght-i+1)/2+1) {
following = currentLetter;
break;
}
else
if (letter[currentLetter]!=0 && currentLetter!=previous && currentLetter<following)
following = currentLetter;
printf("%c",following);
letter[following]--;
previous = following;
}
return 0;
}