2017ecjtu-summer training #2 POJ2503

 
                                                                                                                                                           Babelfish
Time Limit: 3000MS Memory Limit: 65536K
Total Submissions: 44537 Accepted: 18800

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 ogday
cat atcay
pig igpay
froot ootfray
loops oopslay

atcay
ittenkay
oopslay

Sample Output

cat
eh
loops

Hint

Huge input and output,scanf and printf are recommended.
题意:翻译外文,根据输入的单词从字典里查找并输出对应的英文。
该题做法很多,难点在于输入,本菜鸟用了二分查找

AC代码
 1 #include <stdio.h>
 2 #include <math.h>
 3 #include <string.h>
 4 #include <stdlib.h>
 5 #include <iostream>
 6 #include <sstream>
 7 #include <algorithm>
 8 using namespace std;
 9 struct info
10 {
11     char e[20];
12     char f[20];
13 }d[100005];
14 bool compare(const info &a,const info &b)
15 {
16     return strcmp(a.f,b.f)<0;
17 }
18 int main()
19 {
20     char a[50];
21     int i,j,k=0;
22     while(gets(a))
23     {
24         if(a[0]=='\0')
25             break;
26         sscanf(a,"%s%s",d[k].e,d[k].f);
27         k++;
28     }
29     sort(d,d+k,compare);
30     while(gets(a))
31     {
32         int left,right,mid,n=1;
33         left=0;right=k-1;
34         while(left<=right)
35         {
36             mid=(left+right)/2;
37             if(strcmp(a,d[mid].f)==0)
38             {
39               printf("%s\n",d[mid].e);
40               n=0;
41               break;
42             }
43             else if(strcmp(a,d[mid].f)<0)
44                 right=mid-1;
45             else
46                 left=mid+1;
47         }
48         if(n)
49             printf("eh\n");
50     }
51     return 0;
52 }

 



转载于:https://www.cnblogs.com/stranger-/p/7128035.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值