Pagini recente » Cod sursa (job #2161696) | Cod sursa (job #2407261) | Cod sursa (job #253372) | Cod sursa (job #661409) | Cod sursa (job #1002962)
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
const int NMAX = 1000010;
int N, Freq[30], Last = -1;
char S[NMAX];
int main()
{
freopen("ordine.in", "r", stdin);
freopen("ordine.out", "w", stdout);
gets(S + 1);
N = strlen(S + 1);
for(int i = 1; i <= N; ++ i)
Freq[ S[i] - 'a' ] ++;
for(int i = 1; i <= N; ++ i)
{
bool Found = 0;
for(int j = 0; j < 26 && !Found; ++ j)
if(j != Last && Freq[j] == (N - i + 1) / 2 + 1)
{
Freq[j] --;
Last = j;
printf("%c", j + 'a');
Found = 1;
}
if(!Found)
{
for(int j = 0; j < 26; ++ j)
if(j != Last && Freq[j])
{
printf("%c", j + 'a');
Freq[j] --;
Last = j;
break;
}
}
}
}