http://poj.org/problem?id=3007
1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 #define maxn 600000 5 using namespace std; 6 7 struct node 8 { 9 char s[1000]; 10 node *next; 11 }; 12 int ans; 13 node *hash[maxn]; 14 15 void insert(char s[]) 16 { 17 int k=strlen(s); 18 int sum=0; 19 for(int i=0; i<k; i++) 20 { 21 sum+=s[i]*i; 22 } 23 //printf("%d %s ",sum,s); 24 if(!hash[sum]) 25 { 26 node *p=new node(); 27 strcpy(p->s,s); 28 hash[sum]=p; 29 ans++; 30 //printf("*%d %s ",sum,s); 31 } 32 else 33 { 34 node *p=hash[sum]; 35 if(!strcmp(p->s,s)) return ; 36 else 37 { 38 while(p->next!=NULL) 39 { 40 if(!strcmp(p->next->s,s)) 41 return ; 42 p=p->next; 43 } 44 node *q=new node(); 45 strcpy(q->s,s); 46 p->next=q; 47 ans++; 48 //printf("*%d %s ",sum,s); 49 } 50 } 51 return ; 52 } 53 54 void change(char s1[],char s2[],char s3[],char s4[]) 55 { 56 int k1=strlen(s1); 57 int k2=strlen(s2); 58 int t1=0,t2=0; 59 for(int i=k1-1; i>=0; i--) 60 { 61 s3[t1++]=s1[i]; 62 } 63 s3[t1]='