Cod sursa(job #292438)

Utilizator klamathixMihai Calancea klamathix Data 31 martie 2009 10:02:29
Problema Ordine Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.31 kb
#include<stdio.h>
#include<algorithm>
#include<string.h>

#define MAXN 1000000

using namespace std;

int i , j , N , top , max , mark[50], second;
char c, sir[MAXN];

int main()
{
    FILE*in=fopen("ordine.in","r");
    FILE*out=fopen("ordine.out","w");
    /*
    while(!feof(in))
    {
                    fscanf(in ,"%c",&sir[++N]);
                    mark[int(sir[N]) - 97] ++;
    }
    */
    fscanf(in,"%s",&sir);
    N = strlen(sir);
    i = 1;
    
    //fprintf(out,"%d",int('b'));
    
    for( i = 0 ; i < N; i++)
         mark[int(sir[i]) - 97 + 1] ++;
             
   /* for( i = 1; i <= 26; i++)
    fprintf(out,"%d\n",mark[i]);
   */
 //   N = strlen(sir);
    i = 1;
    
    while(!mark[i])
     i++;
    
    top = i;
    i++;
    
    while(!mark[i])
     i++;
     
     second = i;
   
   N = strlen(sir);  
     while(N > 0)
     {
      if(N > 1)
           fprintf(out,"%c%c",char(top + 97 - 1),char(second + 97 - 1));
       else fprintf(out,"%c",char(top + 97 - 1));
       
      N -=2;
     
      mark[top]--; mark[second]--;
      if(!mark[top])
           while(!mark[top]||top == second)
            top++;
      
      if(!mark[second])
            while(!mark[second]||second == top)
             second++;
     }
     
return 0;
}