Cod sursa(job #2296114)

Utilizator Moise_AndreiMoise Andrei Moise_Andrei Data 4 decembrie 2018 13:35:26
Problema Ordine Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.6 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 = '0', t;
int main()
{
    in >> s;
    int sze = strlen(s);
    for(int i = 0; i < sze; i++)
        fr[s[i] - 'a']++;
    for(int i = 0; i < sze; i++)
    {
        t = '0';
        for(int j = 0; j < 26; j++)
            if((fr[j] > 0 && j + 'a' != ant && t == '0') || (fr[j] >= (sze - i) / 2 + 1 && j + 'a' != ant))
                t = j + 'a';
        fr[t - 'a']--;
        v[i] = t;
        ant = t;
    }
    out << v;
    return 0;
}