很水的一道题,但是处理两行之间的空格花了许多功夫,最后还是用了char,因为可以自由修改,相比string需要用insert函数,更加灵活一些。也可以用hash来做,不过有些麻烦就是了。
#include #include #include #include using namespace std; int main() { char d1[50],d2[50]; string tp; map 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::iterator p=dic.find(tar); if(p==dic.end()) cout<<"eh"<