Cod sursa(job #3371746)

Utilizator bucurmihneaBucur Mihnea David bucurmihnea Data 31 octombrie 2026 13:56:24
Problema Litere Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.41 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("litere.in");
ofstream fout("litere.out");
int main()
{
    int n, f[26] = {};
    fin >> n;
    char s[10001];
    fin >> s;
    long long c = 0;
    for(int i = n - 1; i >= 0; i--){
        int poz = s[i] - 'a';
        for(int j = 0; j < poz; j++)
            c += f[j];
        f[poz]++;
    }
    fout << c;

    return 0;
}