Cod sursa(job #110394)

Utilizator gabitzish1Gabriel Bitis gabitzish1 Data 26 noiembrie 2007 18:12:39
Problema Ordine Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#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++;
			printf("%c",j+'a');
			a[j]--;
			n--;
		}
        if (j == 27){ printf("%c",i+'a'); break;}
	}
	printf("\n");
	return 0;
}