Cod sursa(job #1784269)

Utilizator giotoPopescu Ioan gioto Data 19 octombrie 2016 21:48:52
Problema Litere Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.42 kb
#include <cstdio>
using namespace std;

int n, v[10002];
char s[10002];
int main()
{
    freopen("litere.in", "r", stdin);
    freopen("litere.out", "w", stdout);
    scanf("%d", &n); scanf("%s", s);
    int Sol = 0;
    for(int i = 0 ; i < n ; ++i){
        int x = s[i] - 'a';
        for(int j = x + 1; j <= 26 ; ++j)
            Sol += v[j];
        ++v[x];
    }
    printf("%d", Sol);
    return 0;
}