Babelfish POJ - 2503

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;
	}

}

  

猜你喜欢

转载自www.cnblogs.com/zdw20191029/p/11768778.html
今日推荐