Cod sursa(job #125528)

Utilizator alex_mircescuAlex Mircescu alex_mircescu Data 20 ianuarie 2008 14:21:07
Problema Restante Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>

long len, i, n, v[32], j, lgt[36010], sol, d[36010];
char st[32], h[36010][32];

struct grup {
	char nume[32];
};

grup v_s[36010];

int cmp(const void *a, const void *b) {
	return ( *(int *)a - *(int *)b );
}

int cmpf(const void *a, const void *b) {
	return ( strcmp(((grup *)a) -> nume, ((grup *)b) -> nume) );
}

int main() {
	freopen("restante.in", "r", stdin);
	freopen("restante.out", "w", stdout);
	scanf("%ld", &n);
	for (i = 1; i <= n; ++i) {
		scanf("%s", st);
		len = strlen(st);
		v[0] = 0;
		for (j = 0; j < len; ++j) {
			v[++v[0]] = (long)(st[j] - 'a' + 1);
		}
		qsort(v + 1, v[0], sizeof(v[0]), cmp);
		for (j = 1; j <= v[0]; ++j) {
			h[i][j - 1] = (char)(v[j] + 'a' - 1);
		}
		strcpy(v_s[i].nume, h[i]);
	}
	qsort(v_s, n + 1, sizeof(v_s[0]), cmpf);
	for (i = 2; i <= n; ++i) {
		if (strcmp(v_s[i].nume, v_s[i - 1].nume) == 0) {
			d[i - 1] = 1;
		}
	}
	for (i = 1; i <= n; ++i) {
		if (d[i] != 1 && d[i - 1] != 1) {
			++sol;
		}
	}
	printf("%ld\n", sol);
	return 0;
}