PersonalCorpus 版 (精华区)
41325 2002-10-13 20:02:40 Accepted
1109 C++ 00:00.72 2440K Big Guava
int cmp (const void *a , const void *b)
{
return memcmp(a,b,10);
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("c:\\0acm\\zju\\i1109","r",stdin);
freopen("c:\\0acm\\zju\\o1109","w",stdout);
#endif
char s[100010][21],t[100];
int i,j,k,l,m;
memset(s,0,sizeof(s));
k=-1;
while (1) {
gets(t);
if (t[0]==0) break; else k++;
i=0; j=10; while (t[i]!=' ') { s[k][j]=t[i]; i++; j++; }
j=0; i++; while (t[i]!=0) { s[k][j]=t[i]; i++; j++; }
}
qsort(s,k+1,21,cmp);
while (1) {
memset(t,0,10);
if (gets(t)==NULL) break;
i=0;j=k;
while (i<j) {
m=(i+j)/2;
l=cmp(s[m],t);
if (l>0) j=m-1;
else if (l<0) i=m+1;
else { i=m; j=m; }
}
if ((i==j)&&(cmp(s[i],t)==0)) printf("%s\n",s[i]+10); else
printf("eh\n");
}
}
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:12.808毫秒