#include <stdio.h> #include <string.h> #include <stdlib.h> #include <conio.h> #define N 100004
typedef struct { char engl[12]; char fore[12]; }word; word words[N];
int cmp(const void *p, const void *q) { word *a = (word *)p; word *b = (word *)q; return strcmp(a->fore, b->fore); }
int main() { int i, j, re; char ch[30]; //这里本来数组开小了。搞出个破坏栈的错误,找好久。。 char *p; word *q, key;
freopen("in.txt", "r", stdin); i = 0; while(strcmp(gets(ch), "") != 0) { p = strtok(ch, " "); //这里是把英文单词跟外语单词分开来 strcpy(words[i].engl, p); p = strtok(NULL, " "); strcpy(words[i].fore, p); i++; } qsort(words, i, sizeof(words[0]), cmp); while(scanf("%s", ch)!=EOF) { strcpy(key.fore, ch); q = (word*)bsearch(&key, words, i, sizeof(words[0]), cmp); if(q) printf("%s\n", q->engl); else printf("eh\n"); } getch(); return 0; }
|