Pagini recente » Cod sursa (job #1271437) | Cod sursa (job #2683050) | Cod sursa (job #2669666) | Cod sursa (job #1449958) | Cod sursa (job #127223)
Cod sursa(job #127223)
#include <stdio.h>
#include <string.h>
long found, i, j, n, count[30], rez[10001];
char s[10001];
int main()
{
freopen ("ordine.in", "rt", stdin);
freopen ("ordine.out", "wt", stdout);
fgets(s, 10001, 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;
}