Cod sursa(job #2433445)
Utilizator | Porumb Palincas Ionut Ionut28 | Data | 27 iunie 2019 14:22:34 |
---|---|---|---|
Problema | Litere | Scor | 40 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.66 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()
{
for(int i = 0; i < n - 1; ++i)
{
bool ok = false;
for(int j = 0; j < n - i - 1; j++)
if(s[j] > s[j + 1])
{
swap(s[j], s[j + 1]);
ok = true;
sol++;
}
if(!ok)
break;
}
fout << sol;
}
int main()
{
read();
bubble_sort();
return 0;
}