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水了一下,感觉空行结束太没有爱了害我纠结了半天

 #include<cstdio>
#include<iostream>
#include<map>
using namespace std;
int main()
{
map<string,string>mapp;//map,不解释
char ch,s[],p[];
while(scanf("%c",&ch))
{
if(ch=='\n')break;//解决那个烦人的空行结束
s[]=ch;
scanf("%s",s+);
scanf("%s",p);
getchar();
mapp.insert(pair<string,string>(p,s));//插入语句
}
map<string,string>::iterator iter;//声明迭代器,别问我什么用,我也不知道
while(~scanf("%s",s))
{
iter=mapp.find(s);//查找啊
if(iter!=mapp.end())//这个说明找到了
printf("%s\n",iter->second.c_str());//打印出来,别忘了后面的.c_str();
else
printf("eh\n");
}
return ;
}
上一篇:sql server内置存储过程、查看系统信息


下一篇:appium()-java-client-api