对两个字符串变量进行映射。
完成查找,输出。
使用STL的map容器。
注意string对象的操作,与char数组间的转换,及容器的操作方法
#include<iostream>
#include<map>
#include<string>
using namespace std;
map<string,string>Map;
string str1,str2;
char str[100],c_str1[50],c_str2[50];
int main(){
while(gets(str)&&str[0]!='\0'){
sscanf(str,"%s %s",c_str1,c_str2);
str1.assign(c_str1);
str2.assign(c_str2);
Map[str2]=str1;
}
while(scanf("%s",str)!=EOF){
str1.assign(str);
// map<string,string>::iterator ret = Map.find(str1);
// if(ret==Map.end())
if(Map.find(str1)==Map.end())
puts("eh");
else
// puts((*ret).second.c_str());
cout<<Map[str]<<endl;
}
return 0;
}