Cod sursa(job #2296110)

Utilizator Moise_AndreiMoise Andrei Moise_Andrei Data 4 decembrie 2018 13:31:00
Problema Ordine Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <bits/stdc++.h>
using namespace std;
ifstream in("ordine.in");
ofstream out("ordine.out");
int fr[30];
char s[1000005], v[1000005], ant, t;
int main()
{
    in >> s;
    for(int i = 0; i < strlen(s); i++)
        fr[s[i] - 'a']++;
    for(int i = 0; i < strlen(s); i++)
    {
        t = 'a';
        for(int j = 0; j < 26; j++)
            if((fr[j] > 0 && j + 'a' != ant && t == 'a') || (fr[j] >= (strlen(s) - i) / 2 + 1 && j + 'a' != ant))
                t = j + 'a';
        fr[t - 'a']--;
        v[i] = t;
        ant = t;
    }
    reverse(v, v + strlen(v));
    out << v;
    return 0;
}