题解 | #魔咒词典#

魔咒词典

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

#include "map"
#include "iostream"
#include "cstring"
#include <algorithm>
#include <cstdio>
#include <string>
using namespace std;
const int N = 100010;
map<string, string > cidian ;
int n;
int main() {
    string plus;
    while (getline(cin, plus)) {
        string mozhou, func;
        if (plus == "@END@") break;;
        int p2 = plus.find(']');
        mozhou = plus.substr(0,p2+1);
        func = plus.substr(p2 + 2);
        cidian[mozhou] = func;
        cidian[func] = mozhou;
    }
    scanf("%d", &n);
    getchar();
    while (n--) {
        string test;
        getline(cin, test);
        string ans=cidian[test];
        if (ans=="") {
            ans="what?";
        } else if(ans[0]=='['){
            ans= ans.substr(1,ans.size()-2);
        }
        cout << ans <<endl;
    }

    return 0;
}

哈希表

全部评论

相关推荐

不愿透露姓名的神秘牛友
06-29 17:30
找实习找着找着就要进入7月了,马上秋招也要开始了,找实习还有意义吗?
绝迹的星:有面就面, 没面上就当日薪4位数大佬免费培训, 面上了再考虑要不要实习
点赞 评论 收藏
分享
废物一个0offer:认真的吗二本本科找人工智能岗位
点赞 评论 收藏
分享
zYvv:双一流加大加粗再标红,然后广投。主要是获奖荣誉不够,建议开始不用追求大厂,去别的厂子刷下实习。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务