哈希——魔咒字典

魔咒词典

https://www.nowcoder.com/practice/c6ca566fa3984fae916e6d7beae8ea7f?tpId=40&rp=1&ru=%2Fta%2Fkaoyan&qru=%2Fta%2Fkaoyan%2Fquestion-ranking&gioEnter=menu

#include<iostream>
#include<cstdio>
#include<map>
#include<string>
     
using namespace std;
 
map<string, string> dictionary;

int main(){
    string str;
    while(getline(cin, str)){                //因为中间有空格,所以用getline来输入一行
        if(str=="@END@")
            break;
        int pos=str.find("]");
        string key=str.substr(0,pos+1);                //魔咒段
        string value=str.substr(pos+2);                //功能段
        dictionary[key]=value;
        dictionary[value]=key;        //输出魔咒对应的功能,或者功能对应的魔咒
    }
    int n;
    scanf("%d",&n);
    getchar();                        //吃掉会出
    while(n--){
        string key;                //这里的key代表的是value or key
        getline(cin,key);
        string answer=dictionary[key];
        if(answer=="")                        //双引号的表示类型为字符串类型
            answer="what?";
        else if(answer[0] =='[')            //单引号的表示类型为字符类型,字符串的第一个字符为【
            answer=answer.substr(1,answer.size()-2);
        cout<<answer<<endl;
    }
    return 0;
}
全部评论

相关推荐

大飞的诡术妖姬:之前看b站多明海有个说法,日本就业竞争非常低的原因不光是毕业学生少,还有很多人干两年不喜欢职场氛围就辞职躺平,位置也空了很多,论吃苦耐劳还得看咱们
点赞 评论 收藏
分享
05-19 15:21
已编辑
华南农业大学 Java
白火同学:你才沟通了200,说实话,北上广深杭这里面你连一座城市的互联网公司都没投满呢,更别说还有各种准一线二线城市了。等你沟通突破了三位数,还没结果再考虑转行的事吧。
点赞 评论 收藏
分享
白火同学:大二有这水平很牛了,可以适当对关键信息加粗一点,比如关键技术、性能指标之类的。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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