Cod sursa(job #116835)

Utilizator albuaAlbu Alexandru albua Data 19 decembrie 2007 18:23:08
Problema Litere Scor 0
Compilator c Status done
Runda Arhiva de probleme Marime 0.49 kb
#include <stdio.h>
#include <string.h>

char l[10001], aux;
int i, n, ultim, ordonat;
long contor;

FILE *f, *g;

int main()
{
  f = fopen("litere.in", "r");
  g = fopen("litere.out", "w");
  fscanf(f, "%s\n", &l);
  n=strlen(l);
  while (!ordonat)
    {
	  ordonat=1;
	  for (i=0; i<n-1; i++)
	    if (l[i]>l[i+1])
		  {
		    ordonat = 0;
			aux = l[i];
			l[i] = l[i+1];
			l[i+1] = aux;
			contor++;
		  }
	}
  fprintf(g, "%ld\n", contor);
  fclose(g);
  return 0;
}