Cod sursa(job #2011217)

Utilizator stefdascalescuStefan Dascalescu stefdascalescu Data 15 august 2017 17:05:48
Problema Ordine Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.05 kb
#include<bits/stdc++.h>
using namespace std;
ifstream f("ordine.in");
ofstream g("ordine.out");
int poz,l,v[30];
char c1[1000002];
int main()
{
    f>>c1;
    l=strlen(c1);
    for(int i=0;i<l;++i)
        v[c1[i]-'a']++;
    for(int i=0;;++i)
        if(v[i])
        {
            char c='a'+i;
            g<<c;
            --v[i];
            poz=i;
            --l;
            break;
        }
    while(l>0)
    {
        bool ok=0;
        for(int j=0;j<poz;++j)
            if(v[j]>0)
            {
                char c='a'+j;
                g<<c;
                --v[j];
                poz=j;
                --l;
                ok=1;
                break;
            }
        if(ok==0)
            for(int j=poz+1;j<26;++j)
                if(v[j]>0)
                {
                    char c='a'+j;
                    g<<c;
                    --v[j];
                    poz=j;
                    --l;
                    ok=1;
                    break;
                }
    }
    return 0;
}