Pagini recente » Cod sursa (job #1397906) | Cod sursa (job #2622491) | Cod sursa (job #2033335) | Cod sursa (job #2011691) | Cod sursa (job #127225)
Cod sursa(job #127225)
#include <stdio.h>
#include <string.h>
long found, i, j, n, count[30], rez[1000100];
char s[1000100];
int main()
{
freopen ("ordine.in", "rt", stdin);
freopen ("ordine.out", "wt", stdout);
fgets(s, 1000100, stdin);
n = strlen(s) - 1;
for (i = 0; i <= n; i ++)
count[s[i] - 'a']++;
found = 0;
for (j = 0; j <= 25; j ++)
if (count[j] == (n + 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 = 1; i <= n; i ++)
{
found = 0;
for (j = 0; j <= 25; j ++)
if (count[j] == ((n + 1) - (i + 1)) / 2 + 1 && j != rez[i - 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;
}