Cod sursa(job #2558723)

Utilizator Alex_AeleneiAlex Aelenei Ioan Alex_Aelenei Data 26 februarie 2020 19:21:06
Problema Ordine Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <fstream>
#include <iostream>

using namespace std;

int f [ 30 ] ;

int main()
{
    freopen ( "ordine.in" , "r" , stdin ) ;
    freopen ( "ordine.out" , "w" , stdout ) ;

    int n = 0 , i , j ;
    char ch , ant = - 1 ;

    while ( scanf ( "%c" , & ch ) != EOF  && ch != '\n' )
        ++ n , ++ f [ ch - 'a' ] ;

    for ( i = 1 ; i <= n ; ++ i )
    {
        for ( j = 0 ; j < 26 ; ++ j )
            if ( j != ant && f [ j ] )
            {
                ant = j ; -- f [ j ] ;
                printf ( "%c" , j + 'a' ) ;
            }
    }
    return 0;
}