Cod sursa(job #533247)

Utilizator feelshiftFeelshift feelshift Data 13 februarie 2011 16:08:17
Problema Ordine Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <fstream>
#include <string>
using namespace std;

ifstream in("ordine.in");
ofstream out("ordine.out");

string word;
int letter[200];
int i,lenght;
char currentLetter,previous,following;

int main() {
	in >> word;
	lenght = word.size() - 1;

	for (i = 0; i <= lenght; ++i)
		letter[word[i]]++; 
	previous = ' ';

	for (i = 0; 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;
		out << following;
		letter[following]--;
		previous = following;
	}

	return 0;
}