F - Babelfish 문제 풀이 보고서(map 함수)(진연)

F - Babelfish
Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
Submit 
Status
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.
이 제목은 c++의 라이브러리 함수 맵 함수로 일대일 매핑 관계를 구축할 수 있습니다. 구체적인 맵 함수 사용법은 그룹 공유를 보십시오.
#include<iostream>
#include<map>
#include<string>
using namespace std;
int main()
{
	map<string,string> search;// map  search
	char *a,*b;
	char line[1001];
	while(1)
	{
		gets(line);
		if(strlen(line)==0)
			break;
		a=strtok(line," ");// 
		b=strtok(NULL," ");// 
		search[string(b)]=string(a);// 
	}
	string word;
	while(cin>>word)
	{
		string result=search[word];// 
		if(result=="")
			result="eh";
		cout<<result<<endl;
	}
	return 0;
}

좋은 웹페이지 즐겨찾기