Pagini recente » Cod sursa (job #2681677) | Cod sursa (job #3230444) | Cod sursa (job #1536640) | Cod sursa (job #2183986) | Cod sursa (job #2433496)
#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;
}