Cod sursa(job #109835)

Utilizator toni2007Pripoae Teodor Anton toni2007 Data 25 noiembrie 2007 12:47:10
Problema Ordine Scor 0
Compilator cpp Status done
Runda preONI 2008, Runda 1, Clasele 5-8 Marime 0.68 kb
#include<stdio.h>
int s[26];
int main(){
    int n,i,j=-1,k=0;
	char c,t[26];
    freopen("ordine.in","r",stdin);
    freopen("ordine.out","w",stdout);
	for (c='a';c<='z';++c){
		++j;
		t[j]=c;
	}		
    while (!feof(stdin)){
          scanf("%c",&c);
          ++(s[c-'a']);
		  ++k;
	}
	--s[c-'a'];--k;i=0;
	while (k>0){
		while (s[i]==0 && i<=26)
			++i;
		if (i==c){
			++i;
			while (s[i]==0 && i<=26)
				++i;
		}
		printf("%c",t[i]);
		--s[i];++i;--k;
		if (k==0)
			return 0;
		while (s[i]==0 && i<=26)
			++i;
		printf("%c",t[i]);
		--s[i];c=i,i=0;--k;
	}		
	//for (i=0;i<27;++i)
		//printf("%d ",s[i]);
	fclose(stdin);
	fclose(stdout);
    return 0;
}