Pagini recente » Rezultatele filtrării | Cod sursa (job #110401)
Cod sursa(job #110401)
#include <stdio.h>
#include <string.h>
int a[30], n;
int main()
{
freopen("ordine.in","r",stdin);
freopen("ordine.out","w",stdout);
char x;
scanf("%c",&x);
do
{
a[x - 'a']++;
n++;
scanf("%c",&x);
} while (x != '\n');
int i, j;
i = 0;
while (n>0)
{
j = i+1;
while (!a[j] && j<27) j++;
while (a[i] && a[j]) { printf("%c%c",i+'a',j+'a'); n-=2; a[i]--, a[j]--;}
if (!a[i])
{
i = j;
while (!a[i] && i<27) i++;
j = i + 1;
while (!a[j] && j<27) j++;
if (j < 27)
{
printf("%c",j+'a');
a[j]--;
n--;
}
}
if (j == 27 && i < 27){ printf("%c",i+'a'); break;}
}
printf("\n");
return 0;
}