Cod sursa(job #337137)

Utilizator iulia609fara nume iulia609 Data 2 august 2009 17:49:42
Problema Restante Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.61 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 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;
}
*/

void qsort(int in, int sf)
{ int i, j,aux;
  char temp[cif];

	i = in;
	j = sf;
	memcpy(temp, A[(rand()%(sf-in+1)+in)], sizeof(temp));
	
	do {
		
		while(memcmp(A[i], temp, sizeof(temp)) < 0) i++;
		while(memcmp(A[j], temp, sizeof(temp)) > 0) j--;
		if(i < j) {memcpy(s, A[i], sizeof(s)); memcpy(A[i], A[j], sizeof(s)); memcpy(A[j], s, sizeof(s));}
		if(i <= j)i++, j--;
		} while(i <= j) ;
	
	if(in < j) qsort(in, j);
	if(i < sf) qsort(i, sf);
}

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], sizeof(A));
			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 = memcmp(A[i], A[i-1], max);
		
		 if(ok==0) k++;
		}
	
	
	fprintf(g, "%d\n", n-k*2);
	
	
	fclose(f);
	fclose(g);
	return 0;
}