Cod sursa(job #3369158)

Utilizator trickyLupu Alexandru tricky Data 17 octombrie 2026 14:50:13
Problema Litere Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.4 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("litere.in");
ofstream fout("litere.out");

int main() {
    int n, x, f[26] = {0};
    char c;
    long long nr = 0;
    fin >> n;
    for(int i = 1; i <= n; i++) {
        fin >> c;
        int x = c - 'a';
        for (int j = x + 1; j < 26; j++) {
            nr += f[j];
        }
        f[x]++;
    }
    fout << nr;
    return 0;
}