Cod sursa(job #249015)

Utilizator zalmanDanci Emanuel Sebastian zalman Data 27 ianuarie 2009 12:03:04
Problema Restante Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.58 kb
#include<stdio.h>
#include<string.h>
#define fin "restante.in"
#define fout "restante.out"
#define L 361
#define l 26
char v[L][l], aux[l], enter[l];
int n, i, j, count, sw;

void quicksort(char a[], int l, int r)
{
 int i = l-1, j = r;
 int dim = 30;
 char v[dim], aux[dim];
 strcpy(v, a[r]);

 if( r <= l )
  return;

 for( ; ; )
 {
  while (strcmp(a[++i],v) <0 );
  while (strcmp(v, a[--j]) < 0 )
   if( j == l)
	break;
   if( i >= j)
	break;

 // swap(a[i], a[j]);
   strcpy(aux, a[i]);
   strcpy(a[i], a[j]);
   strcpy(a[j], aux);

 }

// swap( a[i], a[r]);
  strcpy(aux, a[i]);
  strcpy(a[i], a[j]);
  strcpy(a[j], aux);

 quicksort( a, l, i-1);
 quicksort( a, i+1, r);
}

void sort_cuv(char s[])
{
 char aux;
  for(int i = 0 ; i<strlen(s) - 1; i++)
   for(int j = i+1; j<strlen(s); j++)
	if( s[i] > s[j])
	{
	  aux = s[i];
	  s[i] = s[j];
	  s[j] = aux;
	}
}

int main(void)
{
 freopen(fin, "r", stdin);
 freopen(fout, "w", stdout);

 scanf("%d", &n);
 gets(enter);
 for( i=1; i<=n; i++)
  {
	gets(v[i]);
	sort_cuv(v[i])0;
  }

  /*for( i=1; i<n; i++)
   for( j=i+1;j<=n; j++)
	if( strcmp(v[i], v[j]) > 0)
	{
	  strcpy(aux, v[i]);
	  strcpy(v[i], v[j]);
	  strcpy(v[j], aux);
	}*/
  quicksort(a, 1, n);

  for(i=1; i<n; i++)
   {
	sw = 0;
	for( j= i+1; j<=n; j++)
	 if( !strcmp( v[i], v[j]))
	   {
		strcpy( v[j] ," ");
		sw++;
	   }
	if(sw)
	 strcpy(v[i], " ");
   }

 for( i = 1 ; i<=n ;i++)
  if( !strcmp(v[i], " ") )
   continue;
  else
   count++;

 printf("%d\n", count);

 fcloseall();
 return 0;

}