Pagini recente » Cod sursa (job #1815077) | Cod sursa (job #1684195) | Cod sursa (job #3147186) | Cod sursa (job #1286501) | Cod sursa (job #127207)
Cod sursa(job #127207)
#include <stdio.h>
#include <string.h>
long found, i, j, n, count[30], rez[10000];
char s[10000];
int main()
{
freopen ("ordine.in", "rt", stdin);
freopen ("ordine.out", "wt", stdout);
fgets(s, 10000, stdin);
n = strlen(s) - 2;
for (i = 0; i <= n; i ++)
count[s[i] - 'a']++;
for (j = 0; j<= 25; j ++)
if (count[j])
{
rez[0] = j;
count[j] --;
break;
}
for (i = 1; i <= n; i ++)
{
found = 0;
for (j = 0; j <= 25; j ++)
if (count[j] == ((n + 1) - i + 1) / 2 + 1)
{
rez[i] = j;
count[j] --;
found = 1;
break;
}
if (!found)
for (j = 0; j <= 25; j ++)
if (count[j] && j != rez[i - 1])
{
rez[i] = j;
count[j] --;
break;
}
}
for (i = 0; i <= n; i ++)
printf("%c", (char) rez[i] + 'a');
return 0;
}