Cod sursa(job #2566330)

Utilizator Florinos123Gaina Florin Florinos123 Data 2 martie 2020 20:34:00
Problema Ordine Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.11 kb
#include <fstream>
#include <cstring>

using namespace std;

ifstream f ("ordine.in");
ofstream g ("ordine.out");

char s[1000001], aux[1000001], helper;
int fr[27], i, j, n, minim;
bool gasit, ok;

int main()
{
    f.getline(s, sizeof(s)), n = strlen(s);
     for (i=0; s[i]; i++)
         fr[s[i]-'a'+1] ++;

    gasit = false, i = 0, minim = 1;
     while (!gasit)
     {
         if (i == n)
         {
             gasit = true;
             continue;
         }

         ok = false;
         for (j=minim; j<=26 && !ok; j++)
         {
             if (fr[j])
             {
                minim = min(minim, j);
                helper = j + 'a' - 1;
                 if (i == 0)
                 {
                     aux[i] = helper;
                     fr[j] --, i ++;
                     ok = true;
                 }
                 else if (aux[i-1] != helper)
                 {
                     aux[i] = helper;
                     fr[j] --, i ++;
                     ok = true;
                 }
             }
         }
     }
   g << aux;
    return 0;
}