Cod sursa(job #2910041)

Utilizator SeracovanuEdwardSeracovanu Edward SeracovanuEdward Data 17 iunie 2022 18:54:48
Problema Litere Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.49 kb
#include <bits/stdc++.h>

using namespace std;

int n;
string str;
vector <int> cnt(27,0);

int main()
{
    freopen("litere.in","r",stdin);
    freopen("litere.out","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n;
    cin >> str;
    int ans = 0;
    for(int i = 0;i < str.size(); ++i){
        cnt[str[i] - 'a']++;
        for(int j = str[i] - 'a' + 1;j < 26; ++j)
            ans += cnt[j];
    }
    cout << ans;
}