Cod sursa(job #404123)
| Utilizator | Data | 25 februarie 2010 20:17:05 | |
|---|---|---|---|
| Problema | Litere | Scor | 40 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.43 kb |
#include<stdio.h>
#define N 10000
int main()
{
freopen("litere.in","r",stdin);
freopen("litere.out","w",stdout);
char aux,s[N];
int ind=0,i,n,ok,cnt=0;
scanf("%d",&n);
gets(s); gets(s);
do
{
ok=0;
for(i=0; i<n-1-ind; i++)
if(s[i]>s[i+1])
{
ok=1;
aux=s[i];
s[i]=s[i+1];
s[i+1]=aux;
cnt++;
}
ind++;
}
while(ok);
printf("%d\n",cnt);
return 0;
}
