Cod sursa(job #2078235)

Utilizator CodrutLemeniCodrut Lemeni CodrutLemeni Data 29 noiembrie 2017 09:05:34
Problema Litere Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <bits/stdc++.h>

using namespace std;

const int SIGMA = 26 ;

int litRep [ SIGMA ];
int noLit;


int getRec (int pos ){

    int noRep = 0 ;
    for( int i = pos + 1; i < SIGMA ; i++ ){
        noRep += litRep [ i ];
    }
    return noRep ;
}

int main(){

    freopen("litere.in","r",stdin);
    freopen("litere.out","w",stdout);

    scanf("%d\n",&noLit);

    char lit ;
    long long sol = 0 ;
    for ( int i = 0 ; i < noLit ; i++ ){
        scanf("%c",&lit);
        litRep [ lit - 'a' ] ++ ;
        sol += getRec( lit - 'a' );
    }
    printf("%lld",sol);
    return 0;

}