Cod sursa(job #2364571)

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

using namespace std;

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

long int v[10001];

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

    int vf = 0;
    int contor = 0;
    while(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++;
        }
    }
    out << contor;
    return 0;
}