Pagini recente » Cod sursa (job #1644927) | Cod sursa (job #2330802) | Cod sursa (job #1755453) | Cod sursa (job #2729564) | Cod sursa (job #2433445)
#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;
}