码迷,mamicode.com
首页 > 其他好文 > 详细

Babelfish POJ - 2503

时间:2019-10-31 01:16:16      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:cti   map   tchar   cas   div   entry   速度   cin   stand   

BabelfishPOJ - 2503

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.
第一次发博客
这个题我觉得难的地方在于格式输入,任何判断是不是一个空行?
  我的解决办法是先输入一个字符,判断是否为一个换行符,然后在与后面输入的字符串连接起来,由于不知道输入的长度变定义为string类型
但是string只能用cin输入cout输出,所以速度较慢
 
#include<cstdio>
#include<iostream>
#include<map>
#include<string>
using namespace std;
int main()
{
	map<string,string> m;
	char c;
	string str1,str2;
	while(c=getchar(),c!=‘\n‘)
	{
		cin>>str1>>str2;
		str1=c+str1;
		m[str2]=str1;
		getchar();
	}
	while(cin>>str2)
	{
		if(m[str2]!="")
  			cout<<m[str2]<<endl;
  		else
  			cout<<"eh"<<endl;
	}

}

  

Babelfish POJ - 2503

标签:cti   map   tchar   cas   div   entry   速度   cin   stand   

原文地址:https://www.cnblogs.com/zdw20191029/p/11768778.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!