Cod sursa(job #533239)

Utilizator feelshiftFeelshift feelshift Data 13 februarie 2011 16:03:44
Problema Ordine Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.84 kb
# 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]-'0']++; 
	previous = ' ';

	for (i = 1; i <= lenght; ++i) {
		following = 'z';

		for (currentLetter = 'a'; currentLetter <= 'z'; ++currentLetter)
			if (letter[currentLetter-'0']==(lenght-i+1)/2+1) {
				following = currentLetter;
				break;
			}
			else
				if (letter[currentLetter-'0']!=0 && currentLetter!=previous && currentLetter<following)
					following = currentLetter;
		printf("%c",following);
		letter[following-'0']--;
		previous = following;
	}

	return 0;
}