Cod sursa(job #532165)

Utilizator ChallengeMurtaza Alexandru Challenge Data 10 februarie 2011 22:18:47
Problema Ordine Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <fstream>
#include <cstring>

using namespace std;

const char InFile[]="ordine.in";
const char OutFile[]="ordine.out";
const int MaxN=1000111;
const int SIGMA=26;

ifstream fin(InFile);
ofstream fout(OutFile);

char buff[MaxN];
int c[SIGMA],N;

int main()
{
	fin>>buff;
	fin.close();

	N=strlen(buff);
	for(register int i=0;i<N;++i)
	{
		++c[buff[i]-'a'];
	}

	int last=SIGMA;
	for(register int i=0;i<N;++i)
	{
		for(register int j=0;j<SIGMA;++j)
		{
			if(c[j]>0 && last!=j)
			{
				--c[j];
				last=j;
				fout<<(char)(j+'a');
				break;
			}
		}
	}
	fout.close();
	return 0;
}