Cod sursa(job #640571)

Utilizator dutzulBodnariuc Dan Alexandru dutzul Data 25 noiembrie 2011 23:01:59
Problema Ordine Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("ordine.in");
ofstream g("ordine.out");
string s;
char c,c2;
int v[1000005],i,j,p,k,n,nr,poz;
int main()
{
    f>>s;
    n=s.length();

    for(i=0; i<=n-1; i++)
    {
        nr=s[i];
        v[nr]++;
    }



  while (0==0)
    {
        while (v[poz]==0&&poz<200) poz++;
        if (poz>180) break;
        k=poz+1;
        while (v[k]==0) k++;

        while(v[poz]!=0&&v[k]!=0)
        {
            v[k]--;
            v[poz]--;
            c=poz;
            if (c2==c) {c=k;c2=poz;}
            else
            c2=k;
        g<<c<<c2;

        }

    }



    f.close();
    g.close();
    return 0;
}