Cod sursa(job #2433496)
Utilizator | Porumb Palincas Ionut Ionut28 | Data | 27 iunie 2019 16:58:41 |
---|---|---|---|
Problema | Litere | Scor | 40 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.63 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("litere.in");
ofstream fout("litere.out");
const int nmax = 10001;
char s[nmax];
int sol, n;
void read()
{
fin >> n;
fin.get();
fin.getline(s, nmax);
fin.close();
}
void bubble_sort()
{
bool ok = false;
do
{
ok = true;
for(int j = 0; j < n - 1; j++)
if(s[j] > s[j + 1])
{
swap(s[j], s[j + 1]);
ok = false;
sol++;
}
n--;
}while(!ok);
fout << sol;
}
int main()
{
read();
bubble_sort();
return 0;
}