Cod sursa(job #2963316)
Utilizator | Data | 10 ianuarie 2023 20:16:32 | |
---|---|---|---|
Problema | Litere | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.54 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("litere.in");
ofstream fout("litere.out");
int main()
{
int n, aux;
long long cnt=0;
fin >> n;
char v[n];
for(int i=0; i<n; i++) {
fin >> v[i];
for(int j=i-1; j>-1; j--) {
if((int)v[j+1]<(int)v[j]) {
aux=v[j+1];
v[j+1]=v[j];
v[j]=aux;
cnt++;
} else {
break;
}
}
}
fout << cnt;
return 0;
}