Cod sursa(job #1639635)

Utilizator VadretkPap Kristof Vadretk Data 8 martie 2016 13:06:46
Problema Ordine Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    int n,k,x,i,ok,j,t[26]={0};
    char elozo,betu;
    n=0;
    elozo=0;
    ifstream f("ordine.in");
    f>>betu;
    while(!f.eof())
    {
        t[betu-'a']++;
        n++;
        f>>betu;
    }
    f.close();
    ofstream g("ordine.out");
    for(i=0;i<n;i++)
    {
        x=0;
        for(j=0;j<26&&x!=1;j++)
        {
            if(t[j]!=0&&j+'a'!=elozo)
            {
                t[j]--;
                ok=1;
                for(k=0;k<26;k++)
                    if(t[k]>(n-i)/2)
                        ok=0;
                if(ok==1)
                {
                    g<<(char)(j+'a');
                    elozo=j+'a';
                    x=1;
                }
                else
                    t[j]++;
            }
        }
    }
    g.close();
}