Cod sursa(job #3143022)
Utilizator | Data | 26 iulie 2023 22:14:17 | |
---|---|---|---|
Problema | Litere | Scor | 40 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.46 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("litere.in");
ofstream fout("litere.out");
int main(){
int n;
string s;
fin >> n >> s;
int csere=1, vege=n-1, cnt=0;
while(csere!=-1){
csere=-1;
for(int i=0; i<vege; i++){
if(s[i]>s[i+1]){
swap(s[i], s[i+1]);
cnt++;
csere=i;
}
}
vege=csere;
}
fout << cnt;
return 0;
}