Cod sursa(job #2372843)

Utilizator bitonekoTraian Omin bitoneko Data 7 martie 2019 11:18:34
Problema Litere Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.49 kb
#include <fstream>

using namespace std;
ifstream cin("litere.in");
ofstream cout("litere.out");
string s="";
void swap(int x,int y)
{
    int a=s[x],b=s[y];
    s[y]=a;
    s[x]=b;
}
int main()
{
    int n,cnt=0;;
    cin >> n >> s;
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<n-i-1; j++)
        {
            if (s[j]>s[j+1])
            {
                cnt++;
                swap(j,j+1);
            }
        }
    }
    cout << cnt;
    return 0;
}