Cod sursa(job #2515238)

Utilizator memecoinMeme Coin memecoin Data 28 decembrie 2019 09:20:53
Problema Litere Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <fstream>
#include <string>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#include <map>
#include <string.h>
#include <queue>

using namespace std;

#ifdef DEBUG
string name = "data";
#else
string name = "litere";
#endif

ifstream fin(name + ".in");
ofstream fout(name + ".out");

string s;
int n;
int cnt;

int main() {
    
    fin >> n;
    fin >> s;
    
    int change = 0;
    
    for (char c = 'a'; c <= 'z'; ++c) {
        int tc = 0;
        for (int i = 0; i < n; ++i) {
            tc += s[i] > c;
            if (s[i] == c) {
                change += tc;
            }
        }
    }
    
    fout << change;
    
    return 0;
}