Pagini recente » Cod sursa (job #1254121) | Cod sursa (job #3123372) | Cod sursa (job #2318128) | Cod sursa (job #1587563) | Cod sursa (job #1274218)
#include <fstream>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
ifstream fin("ordine.in");
ofstream fout("ordine.out");
char word[1000005];
int appears[30];
int L;
void Sort()
{
int preLast = -1, LastC = -1;
for(int i = 0; i < L; i++)
{
int aux = 0;
while(!appears[aux] || aux == LastC)
aux += 1;
preLast = LastC; LastC = aux;
for(aux = LastC + 1; aux < 26; aux += 1)
{
if(appears[aux] == (L - i) / 2 + 1 && aux != preLast)
LastC = aux;
}
appears[LastC] -= 1;
fout << (char)('a' + LastC);
}
}
void read()
{
fin >> word;
L = strlen(word);
for(int i = 0; i < L; i++)
{
int letter = (int)word[i] - 'a';
appears[letter] += 1;
}
Sort();
}
int main()
{
read();
return 0;
}