Cod sursa(job #2364558)

Utilizator DreeyBurlacu Andrei Dreey Data 4 martie 2019 09:41:22
Problema Litere Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <bits/stdc++.h>

using namespace std;

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

int v[10001];

int main()
{
    int n;
    in >> n;
    in.get();
    char c;

    int vf = 0;
    int contor = 0;
    while(n)
    {
        in >> c;
        v[++vf] = c - 'a';
        int auxvf = vf;
        while(v[auxvf] < v[auxvf-1] && auxvf > 1)
        {
            swap(v[auxvf],v[auxvf-1]);
            auxvf--;
            contor++;
        }
        n--;
    }
    out << contor;
    return 0;
}