what?
#include <stdio.h> #include <string.h> #include <stdlib.h> #define MAXN 100000 typedef struct{ char zy[25]; //神坑:[21]一直WA,浪费我好几小时 char fun[85];//[81]也一直WA }ZY; ZY zys[MAXN]; ZY zys2[MAXN]; int cmp1(const ZY* a,const ZY* b){ return strcmp((*a).zy,(*b).zy); } int cmp2(const ZY* a,const ZY* b){ return strcmp((*a).fun,(*b).fun); } ZY* bsearch1(int low,int high,const ZY *p){ int mid; int ret; while(low <= high){ mid = (low + high) >> 1; ret = cmp1(&zys[mid],p); if(ret == 0){ return &zys[mid]; } else if(ret > 0) high = mid - 1; else low = mid + 1; } return 0; } ZY* bsearch2(int low,int high,const ZY *p){ int mid; int ret; while(low <= high){ mid = (low + high) >> 1; ret = cmp2(&zys2[mid],p); if(ret == 0){ return &zys2[mid]; } else if(ret > 0) high = mid - 1; else low = mid + 1; } return 0; } int main(){ char test[81]; char *end = "@END@"; int i = 0,j = 0,n,cnt,len; char ch; ZY _zy; ZY *_zy1; while(1){ j = 0; while(']' != (ch = getchar()) && '@' != ch) zys[i].zy[j++] = ch; if(ch == '@'){ gets(test); break; } zys[i].zy[j++] = ']'; zys[i].zy[j++] = 0; getchar(); j = 0; gets(zys[i].fun); strcpy(zys2[i].zy,zys[i].zy); strcpy(zys2[i].fun,zys[i].fun); i++; } cnt = i; qsort(zys,i,sizeof(ZY),cmp1); qsort(zys2,i,sizeof(ZY),cmp2); scanf("%d",&n); getchar(); for(i = 0;i < n;++i){ j = 0; gets(test); if(test[0] == '['){ strcpy(_zy.zy,test); _zy1 = bsearch1(0,cnt-1,&_zy); if(_zy1) printf("%s\n",_zy1->fun); else printf("what?\n"); } else{ strcpy(_zy.fun,test); _zy1 = bsearch2(0,cnt-1,&_zy); if(_zy1){ len = strlen(_zy1->zy); _zy1->zy[len-1] = 0; printf("%s\n",_zy1->zy+1); } else printf("what?\n"); } } return 0; }