大意略。
思路:手写一个map容器即可。
#include <iostream> #include <cstdlib> #include <cstdio> #include <cstring> #include <string> #include <set> #include <map> using namespace std; map<string, string> Map; char str[60]; char temp1[30], temp2[30]; void init() { Map.clear(); } void read_case() { init(); while(gets(str)) { if(str[0] == '\0') break; sscanf(str, "%s %s", temp1, temp2); Map[temp2] = temp1; } } void solve() { read_case(); while(gets(str)) { if(Map.find(str) != Map.end()) cout<<Map[str]<<endl; else cout<<"eh"<<endl; } } int main() { solve(); system("pause"); }