Cod sursa(job #532165)
#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;
}