#include <stdio.h>#include<string.h>#include<stdlib.h>#defineM 100001#defineN 100structNode//array of linked lists{ intID; structNode *next;}*D[m]; CharA[m][n],b[m][n];Chars[n],str[n];unsignedintElfhash (Char*str) {unsignedintHash=0; unsignedintx=0; while(*str) {Hash= (hash<<4) + (*str++); if((x=hash&0xf0000000l)!=0) {Hash^= (x>> -); Hash&=~x; } } returnhash%M;}intMain () {intI=0; structNode *p; while(SCANF ("%s", str), strcmp ("@[email protected]", str)) { intlen=strlen (str); Str[len-1]=' /'; strcpy (A[i],str+1);//previous string processingGets (str);//after a string processingstrcpy (b[i],str+1); intHash=elfhash (B[i]);//mapping of the latter stringP= (structNode *)malloc(sizeof(structnode));//Create a dynamic linked list Pp->id=i;//to the valuep->next=d[hash];//Give the first address to the list of the list of linked listsD[hash]=p;//The first address of the linked list P is paid to the list of listHash=elfhash (A[i]);//mapping of the previous string, with the same value as I for two stringsP= (structNode *)malloc(sizeof(structnode)); P->id=i; P->next=D[hash]; D[hash]=p; I++; } intN; scanf ("%d",&N); GetChar (); while(n--) {gets (str); if(str[0]=='[') { intlen=strlen (str); Str[len-1]=' /'; strcpy (S,str+1); } Elsestrcpy (S,STR); intHash=Elfhash (s); P=D[hash]; intflag1=1, flag2=1; while(p) {if(strcmp (b[p->id],s) = =0) {Flag1=0; Break; } if(strcmp (a[p->id],s) = =0) {Flag2=0; Break; } P=p->Next; } if(p) {if(flag1==0) printf ("%s\n",a[p->id]); Elseprintf ("%s\n",b[p->id]); } Elseprintf ("what?\n"); } return 0;}
Hash list of string hashes handling conflicts poj1880