Cod sursa(job #1520288)

Utilizator Moise_AndreiMoise Andrei Moise_Andrei Data 8 noiembrie 2015 16:20:49
Problema Litere Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <iostream>
#include <fstream>

using namespace std;

const int maxalpha = 26;
const int maxn = 10005;

int fr[maxalpha];
char s[maxn];

int main()
{
    ifstream fin("litere.in");
    ofstream fout("litere.out");
    int n;
    fin >> n;
    fin >> s;
    int rasp = 0;
    for(int i = 0 ; i < n ; ++ i) {
        ++ fr[s[i] - 'a'];
        for(int j = s[i] - 'a' + 1 ; j < maxalpha ; ++ j) { /// iau toate caracterele mai mici strict ca numarul meu
            rasp += fr[j];
        }
    }
    fout << rasp << '\n';
    return 0;
}