Cod sursa(job #3369016)

Utilizator teodora999Ringheanu Olivia-Teodora teodora999 Data 17 octombrie 2026 10:01:40
Problema Litere Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.46 kb
#include <iostream>
#include <cstring>
#include <fstream>
using namespace std;

ifstream fin("litere.in");
ofstream fout("litere.out");

int main()
{
    int n, nr = 0, fr[27] = {0};
    char s[10001];

    fin >> n;

    for (int i = 0; i < n; i ++)
    {
        char c;
        fin >> c;

        int x = c - 'a';

        for (int j = x + 1; j <= 26; j ++)
            nr += fr[j];

        fr[x]++;
    }

    fout << nr;
    return 0;
}