Cod sursa(job #337134)

Utilizator iulia609fara nume iulia609 Data 2 august 2009 17:39:21
Problema Restante Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.22 kb
#include<stdio.h>
#include <cstdio>
#include<algorithm>
#include<string.h>
#define dim 36001
#define cif 17
using namespace std;

char  s[cif];
int n,max;
char aux, A[dim][cif];
int O[dim];


/*inline int cmp (const void *a, const void *b)
{
  //int aa = *(int *)a;
 // int bb = *(int *)b;
  return (A[*(int *)a] < A[*(int *)b]) ? -1 : (A[*(int *)a] > A[*(int *)b]) ? 1 : 0;
}
*/

int main()
{ int i, j, m, k,max,ok;
	
	
	FILE *f = fopen("restante.in", "r");
	FILE *g = fopen("restante.out", "w");
	
	fscanf(f, "%d", &n);
	
	max = 0;
	for(i = 1; i <= n; i++)
		{
			fscanf(f, "%s", &s);
			m = strlen(s);
				if(m > max) max = m;
			for(j = 0; j < m; j++) 
				A[i][j] = s[j];
			sort(A[i], A[i]+m);			
		}
	
	
	//qsort(A[1], A[n], sizeof(int), cmp);
	
	
	

	for(i = 1; i <= n-1; i++)
		for(j = i+1; j <= n; j++)
		{
			ok = memcmp(A[i],A[j], max);
			if(ok > 0) {memcpy(s, A[i], max); memcpy(A[i], A[j], max); memcpy(A[j], s, max);}  
		}
	
	
	k = 0;
	for(i = 2; i <= n; i++)
	   {ok = 1;
		for(j = 1; j <= max; j++)
				if(A[i][j] != A[i-1][j]) 
				{
					ok = 0;
					break;
				}	
		 if(ok) k++;
		}
	
	
	fprintf(g, "%d\n", n-k*2);
	
	
	fclose(f);
	fclose(g);
	return 0;
}