Cod sursa(job #115968)
| Utilizator | Data | 17 decembrie 2007 15:23:35 | |
|---|---|---|---|
| Problema | Litere | Scor | 40 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.42 kb |
#include<stdio.h>
#include<string.h>
FILE*f=fopen("litere.in","r");
FILE*g=fopen("litere.out","w");
char v[10003];
long long sol;
int n;
void read()
{
fscanf(f,"%d\n%s",&n,v);
}
void bubble()
{
int i,j,ok;
char aux;
for(i=0;i<n-1;++i)
{
j=i;
while(j>=0&&v[j+1]<v[j])
{
sol++; aux=v[j+1]; v[j+1]=v[j]; v[j]=aux;
j--;
}
}
fprintf(g,"%lld",sol);}
int main()
{
read();
bubble();
return 0;
}
