poj-2503 Babelfish

来源:互联网 发布:网络摄像头拓扑图 编辑:程序博客网 时间:2024/06/08 14:36
                                                          F -Babelfish
Crawling in process...Crawling failedTime Limit:3000MS    Memory Limit:65536KB   64bit IO Format:%I64d & %I64u
SubmitStatusPracticePOJ 2503

Description

You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately, you have a dictionary to help you understand them.

Input

Input consists of up to 100,000 dictionary entries, followed by a blank line, followed by a message of up to 100,000 words. Each dictionary entry is a line containing an English word, followed by a space and a foreign language word. No foreign word appears more than once in the dictionary. The message is a sequence of words in the foreign language, one word on each line. Each word in the input is a sequence of at most 10 lowercase letters.

Output

Output is the message translated to English, one word per line. Foreign words not in the dictionary should be translated as "eh".

Sample Input

dog ogdaycat atcaypig igpayfroot ootfrayloops oopslayatcayittenkayoopslay

Sample Output

catehloops
先定义一个结构体用来储存字典,然后对字典中的英文进行排序,输入单词,进行查找,若找到,输出相对应的英文,若找不到则就输出eh.
#include<stdio.h>  #include<string.h>  #include<stdlib.h>  struct diction{      char eng[11];    char fn[11];};  struct diction a[1000001];     int fcmp(const void * a,const void *b){      return strcmp(((diction*)a)->fn, ((diction*)b)->fn);  }    int cmp(const void* a, const void* b) {      return strcmp((char*)a, ((diction*)b)->fn);  }    int main()  {      int i,j,k,sum,sign,len;      char str[30];      struct diction *p;      sum=0;      sign=0;      while(gets(str))      {          len=strlen(str);          if(len==0)              break;          else          {              for(i=0;i<len;i++)              {                  if(str[i]==' ')       break;                a[sum].eng[i]=str[i];              }              a[sum].eng[i]='\0';             for(j=i+1,k=0;j<len;j++,k++)      a[sum].fn[k]=str[j]; a[sum].fn[k]='\0';              sum++;          }      }      qsort(a,sum,sizeof(diction),fcmp);     while(gets(str))      {          p=(diction*)bsearch(str,a,sum,sizeof(diction),cmp);        if(p)              puts(p->eng);         else              puts("eh");      }     return 0; }  

原创粉丝点击