poj2503 Babelfish

#include<iostream>
#include<cstring>
#include<string>
#include<map>
#include<cstdio>
using namespace std;
char english[12],foreign[12];
int main()
{
	map<string,bool>appear;   //记录foreign与engliash的配对映射是否出现 
	map<string,string>translate;   //记录foreign到engliash的映射  
	 /*Input the dictionary*/ 
	while(true)
	{
		char ch;
		ch=getchar();
		if(ch=='\n')   //判定是否输入了空行
			break;
		else			//输入english 
		{
			int cnt=1;
			english[0]=ch;
			while(true)
			{
				ch=getchar();
				if(ch==' ')
				{
					english[cnt]='\n';
					break;
				}
				else
				{
					english[cnt++]=ch;
				}
			}
			cin>>foreign;
			getchar();   //吃掉 输入foreign后的 回车符 
			appear[foreign]=true;
			translate[foreign]=english;
		}
	}
	char str[12];
	while(cin>>str)
	{
		if(appear[str])
			cout<<translate[str]<<endl;
		else
			cout<<"eh"<<endl;
	}
}

你可能感兴趣的:(poj2503 Babelfish)