Cod sursa(job #579520)
| Utilizator | Data | 12 aprilie 2011 10:49:44 | |
|---|---|---|---|
| Problema | Litere | Scor | 40 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.42 kb |
#include<stdio.h>
char S[10000];
int N;
int nr = 0;
int main()
{
int gata;
char c;
FILE *f = fopen("litere.in","r");
FILE *g = fopen("litere.out","w");
fscanf(f,"%d %s",&N,S);
do
{
gata = 1;
for(int i=0;i<N-1;i++)
if(S[i]>S[i+1])
{
c = S[i];
S[i] = S[i+1];
S[i+1] = c;
nr ++;
gata = 0;
}
} while(!gata);
fprintf(g,"%d",nr);
fclose(g);
fclose(f);
}