Cod sursa(job #300366)

Utilizator ooctavTuchila Octavian ooctav Data 7 aprilie 2009 13:26:06
Problema Ordine Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.76 kb
// ordine.cpp : Defines the entry point for the console application.
//

#include <cstdio>
char c[1000001];
int c2[1000001];
int e[30],curent=0;
int principal=0,secundar=1;
void sortare()
{
	int t;
	c2[0]=-1;
	for(int i=1;i<curent;i++)
		if(c2[i]==c2[i-1])
		{
			t=c2[i];
			c2[i]=c2[i+1];
			c2[i+1]=t;
			if(i>2)
				i=i-2;
			else
				i=1;
		}
}
int main()
{
	freopen("ordine.in","r",stdin);
	freopen("ordine.out","w",stdout);
	int i;
	fgets(c,100000,stdin);
	for(i=0; c[i]!='\n'&& c[i] ;i++)
		e[c[i]-'a']++;
	for(i=0;i<=29;i++)
		while(e[i]--)
		{
			c2[++curent]=i;
			while(!e[secundar])
				secundar++;
			c2[++curent]=secundar;
			e[secundar]--;
		}
	sortare();
	for(i=1;i<=curent;i++)
		printf("%c",c2[i]+'a');
	return 0;
}