Cod sursa(job #1869032)

Utilizator giotoPopescu Ioan gioto Data 5 februarie 2017 15:39:38
Problema Ordine Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <cstdio>
#include <cstring>
using namespace std;

char s[1000005];
int f[28];
int main()
{
    freopen("ordine.in", "r", stdin);
    freopen("ordine.out", "w", stdout);
    scanf("%s", s);
    int L = strlen(s);
    for(int i = 0; i < L ; ++i)
        ++f[s[i] - 'a'];
    int i = 0, Next = 1, k = 0;
    while(i < 26){
        if(f[i] > 0){
            s[k++] = i + 'a';
            --f[i];
            Next = i + 1;
            while(f[i] > 0){
                while(f[Next] == 0)
                    ++Next;
                --f[Next]; --f[i];
                s[k++] = Next + 'a';
                s[k++] = i + 'a';
            }
        }
        ++i;
    }
    printf("%s", s);
    return 0;
}