Cod sursa(job #735135)

Utilizator alex_unixPetenchea Alexandru alex_unix Data 15 aprilie 2012 19:28:53
Problema Litere Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.56 kb

#include <fstream>

int main (void)
{
    unsigned short n;
    std::ifstream input("litere.in");
    input >> n;
    unsigned short v ['z' + 1] = {0};
    char c;
    unsigned int sol(0);
    unsigned short *it,*limit(v + 'z');
    do
    {
        input >> c;
        ++v[c];
        it = v + c + 1;
        while (it < limit)
        {
            if (*it)
                sol += *it;
            ++it;
        }
        --n;
    }
    while (n);
    input.close();
    std::ofstream output("litere.out");
    output << sol << '\n';
    output.close();
    return 0;
}