Babelfish POJ - 2503

Posted zdw20191029

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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!=‘
‘)
	{
		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的主要内容,如果未能解决你的问题,请参考以下文章

POJ2503 Babelfish

POJ 2503Babelfish(水题)stl map存取即可

POJ 2503.Babelfish

Babelfish POJ - 2503

poj 2503 Babelfish

POJ2503-Babelfish-二分