Pagini recente » Cod sursa (job #524931) | Cod sursa (job #2544726) | Cod sursa (job #563395) | Cod sursa (job #3172817) | Cod sursa (job #275595)
Cod sursa(job #275595)
#include<stdio.h>
#include<algorithm>
#include<string.h>
#define nmax 36111
using namespace std;
int n,poz[nmax],p,u,i,nr,aux,N;
char v[nmax][20];
int cmp(int a, int b){
int A = strlen(v[a]), B = strlen(v[b]);
if( A > B ) return 0;
if( B > A ) return 1;
if( strcmp(v[a], v[b]) == 1 ) return 1;
return 0;
}
int egale(int a, int b){
if( strlen( v[a] ) == strlen( v[b] ) && strcmp(v[a],v[b]) == 0 ) return 1;
return 0;
}
void up(int Poz, int n){
int c = Poz,t;
t = c >> 1;
while( cmp( poz[c] , poz[t] ) && t ){
aux = poz[c];
poz[c] = poz[t];
poz[t] = aux;
c = t; t = c >> 1;
}
}
void down(int Poz, int n){
int c,t = Poz;
c = t << 1;
if( c < n && cmp( poz[c+1], poz[c] ) )
c++;
while( c <= n && cmp( poz[c], poz[t] ) ){
aux = poz[c];
poz[c] = poz[t];
poz[t] = aux;
c = t << 1; t = c;
if( c < n && cmp( poz[c+1], poz[c] ) )
c++;
}
}
void sort(){
for(i=2; i<=n; i++)
up(i,i);
for(i=n; i > 1; i--){
aux = poz[i]; poz[i] = poz[1]; poz[1] = aux;
down(1,i-1);
}
}
int main(){
FILE *f = fopen("restante.in","r");
FILE *g = fopen("restante.out","w");
fscanf(f,"%d\n",&n);
for(i=1; i<=n; i++){
fscanf(f,"%s",v[i]);
poz[i] = i;
N = strlen(v[i]);
sort(v[i], v[i] + N);
}
sort();
nr = 1;
for(i=2; i<=n; i++){
p = poz[i-1]; u = poz[i];
if( ! egale (p,u) )
nr++;
}
fprintf(g,"%d",nr);
fclose(f);
fclose(g);
return 0;
}