题解 | 魔咒词典

魔咒词典

https://www.nowcoder.com/practice/c6ca566fa3984fae916e6d7beae8ea7f

#include <iostream>
#include<map>
#include<string>
using namespace std;
//把魔咒一整个的存下来
map<string, string>dic;
int main() {
    string str;
    while (getline(cin, str)) { // 注意 while 处理多个 case
        if (str == "@END@")break;
        //先全部存起来
        int pos = str.find(']');
        string zhouyu_with, mofa,zhouyu;
        zhouyu_with = str.substr(0, pos+1);//要连中括号一起保存,这样的话要简单一点
        zhouyu = str.substr(1, pos -1);
        mofa = str.substr(pos + 2);
        dic[zhouyu_with] = mofa;
        dic[mofa] = zhouyu;
    }
    int n;
    cin >> n;
    getchar();
    while (n--) {
        string key;
        getline(cin, key);
        if (!dic.count(key))printf("what?\n");
        else printf("%s\n", dic[key].c_str());
    }

}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

被普调的六边形战士很高大:项目经历貌似和专业或者求职方向没大关系?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务