很水的一道題,但是處理兩行之間的空格花了許多功夫,最後還是用了char,因為可以自由修改,相比string需要用insert函數,更加靈活一些。也可以用hash來做,不過有些麻煩就是了。
#include <iostream>
#include <string>
#include <map>
#include <cstdio>
using namespace std;
int main()
{
char d1[50],d2[50];
string tp;
map<string,string> dic;
int count=0;
while(1)
{
char t=getchar();
if(t=='\n')
break;
else
{
d1[0]=t;
int i=1;
while(1)
{
t=getchar();
if(t==' ')
{
d1[i]='\0';
break;
}
else
d1[i++]=t;
}
}
cin>>d2;
getchar(); //吃掉 輸入foreign後的 回車符
dic[d2]=d1;
count++;
}
string tar;
while(cin>>tar)
{
map<string,string>::iterator p=dic.find(tar);
if(p==dic.end())
cout<<"eh"<<endl;
else
cout<<(*p).second<<endl;
}
return 0;
}