Cod sursa(job #533223)

Utilizator feelshiftFeelshift feelshift Data 13 februarie 2011 15:41:15
Problema Ordine Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
// http://infoarena.ro/problema/ordine
#include <fstream>
#include <string>
using namespace std;

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

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

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

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

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

		for(char currentLetter='a';currentLetter<='z';currentLetter++)
			if(letter[currentLetter] == (lenght-currentLetter) / 2 + 1) {
				following = currentLetter;
				break;
			}
			else
				if(letter[currentLetter] && currentLetter != previous && currentLetter < following)
					following = currentLetter;

		out << following;
		letter[following]--;
		previous = following;
	}

	return (0);
}