题解 | #魔咒词典#

魔咒词典

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")

全部评论

相关推荐

我已成为0offer的糕手:别惯着,胆子都是练出来的,这里认怂了,那以后被裁应届被拖工资还敢抗争?
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务