![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLiIXZ05WZD9CX5RXa2Fmcn9CXwczLcVmds92czlGZvwVP9EUTDZ0aRJkSwk0LcxGbpZ2LcBDM08CXlpXazRnbvZ2LcRlMMVDT2EWNvwFdu9mZvwVP9c2Ys5EWkZmSYpFMWh0Y0ljMZZXUYpVd1kmYr50MZV3YyI2cKJDT29GRjBjUIF2LcRHelR3LcJzLctmch1mclRXY39DN3gTO1cDN3ETMyATM3EDMy8CX0Vmbu4GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.jpg)
好像沒什麼好說的。。map容器會怎麼用就水過了。。
代碼如下:
#include <map>
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
map<string,string>mp;
const int maxn = 30;
char s[maxn];
void init(){
int len = strlen(s);
string s1 = "";
string s2 = "";
int i = 0;
for (; i<len; i++) {
if (s[i]==' ') break;
s1 += s[i];
}
i++;
for (; i<len; i++) s2 += s[i];
mp[s2] = s1;
}
int main(){
mp.clear();
while (gets(s)) {
if (s[0]=='\0') break;
init();
}
while (gets(s)){
if (mp.find(s)!=mp.end()) cout << mp[s] << endl;
else cout << "eh" << endl;
}
return 0;
}