题解 | #魔咒词典#
魔咒词典
https://www.nowcoder.com/practice/c6ca566fa3984fae916e6d7beae8ea7f
#include <iostream>
#include <map>
using namespace std;
map<string, string> magics;
int main() {
string str;
while (getline(cin, str) && str != "@END@") {
int pos = str.find(']');
string s1 = str.substr(0, pos + 1);
string s2 = str.substr(pos + 2);
magics[s1] = s2;
magics[s2] = s1;
}
int n;
cin >> n;
getchar();//帮getline吃掉回车
while(n --){
getline(cin, str);
string res = magics[str];
if(res == "")
cout << "what?" << endl;
else{
if(res[0] == '[')
cout << res.substr(1, res.size() - 2) << endl;
else
cout << res << endl;
}
}
return 0;
}
