题解 | #魔咒词典#

魔咒词典

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;
}

全部评论

相关推荐

头像
04-29 10:53
已编辑
东北大学 自动化类
点赞 评论 收藏
转发
点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务