题解 | #魔咒词典#
魔咒词典
https://www.nowcoder.com/practice/c6ca566fa3984fae916e6d7beae8ea7f
#include <cstdio> #include <iostream> #include "unordered_map" using namespace std; int main() { string line; unordered_map<string, string> codeMap; unordered_map<string, string> meanMap; while (getline(cin, line)) { // 注意 while 处理多个 case // cout << a + b << endl; if (line == "@END@") { break; } string mean; int pos = line.find(']'); string code = line.substr(1, pos-1); mean = line.substr(pos + 2); codeMap[code] = mean; meanMap[mean] = code; } int n; cin >> n; getchar();//吃掉回车 while (n--) { string lookUp; getline(cin, lookUp); if (lookUp[0] == '[') { lookUp = lookUp.substr(1, lookUp.size() - 2); if (codeMap.find(lookUp) == codeMap.end()) { cout << "what?" << endl; } else { cout << codeMap[lookUp] << endl; } } else { if (meanMap.find(lookUp) == meanMap.end()) { cout << "what?" << endl; } else { cout << meanMap[lookUp] << endl; } } } } // 64 位输出请用 printf("%lld")