题目链接:http://poj.org/problem?id=2503
代码:
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; const int maxn = 100050; const int HASH = 1000003; int head[HASH],next[maxn]; char s1[maxn][15],s2[maxn][15]; int n; int hash(char *s) { int ret = 0; int seed = 131; while(*s) { ret = ret * seed + *(s++); } return (ret & 0x7fffffff) % HASH; } int search(char *s) { int i; int id = hash(s); for(i=head[id]; i!=-1; i=next[i]) { if(strcmp(s,s2[i]) == 0) break; } return i; } void input() { memset(head,-1,sizeof(head)); n = 0; char ch[30]; gets(ch); while(ch[0] != '