Babelfish

Time Limit: 1000MS Memory limit: 65536K
题目描述
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 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 is the message translated to English, one word per line. Foreign words not in the dictionary should be translated as "eh".
示例输入
dog ogday
cat atcay
pig igpay
froot ootfray
loops oopslay

atcay
ittenkay
oopslay示例输出
cat
eh
loops

 

这个题觉得不难,本意是字典树,自己不会,各种水,用数组也可以做,但是一定会超时

用map水了一下,感觉空行结束太没有爱了害我纠结了半天

 

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<map>
 4 using namespace std;
 5 int main()
 6 {
 7     map<string,string>mapp;//map,不解释
 8     char ch,s[15],p[15];
 9     while(scanf("%c",&ch))
10     {
11         if(ch=='\n')break;//解决那个烦人的空行结束
12         s[0]=ch;
13         scanf("%s",s+1);
14         scanf("%s",p);
15         getchar();
16         mapp.insert(pair<string,string>(p,s));//插入语句
17     }
18     map<string,string>::iterator iter;//声明迭代器,别问我什么用,我也不知道
19     while(~scanf("%s",s))
20     {
21         iter=mapp.find(s);//查找啊
22         if(iter!=mapp.end())//这个说明找到了
23             printf("%s\n",iter->second.c_str());//打印出来,别忘了后面的.c_str();
24         else
25             printf("eh\n");
26     }
27     return 0;
28 }
View Code

 

posted @ 2013-08-10 17:42  孔凡凯凯  阅读(240)  评论(0编辑  收藏  举报