觉得浮夸了四年,漠然发现原来是浮躁了四年!

POJ 2503(Babelfish)

Description

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.

Source

 
I didn't work out the problem like that just because I know little about the function of the C++.So the most important thing next is to learn more !I can!  Come on!  Green hand like me!
#include<iostream>
#include<string>
#include<map>
using namespace std;
void Getword(const string &str,string &str1,string &str2)
{
	int i=str.find_first_of(' ');
	str1=str.substr(0,i);
	int j=str.find_first_not_of(' ',i);
	str2=str.substr(j,str.length()-j);
}
map<string,string> map_match;
int main()
{
	string line;
	while(getline(cin,line))
	{
		string english;
		string foreign;
		if(line.length()==0)
		  break;
		Getword(line,english,foreign);
		map_match[foreign]=english;
	}
	while(getline(cin,line))
	{
		int k=map_match.count(line);
		if(k>0)
			cout<<map_match[line]<<endl;
		else
			cout<<"eh"<<endl;
	}
	return 0;
}


  

 
posted @ 2012-10-29 22:31  heat nan  阅读(168)  评论(0)    收藏  举报