题解 | #魔咒词典#

魔咒词典

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

#include <iostream>
#include <map>
#include <string>
using namespace std;
map<string,string> wizd;
int main() {
    string x;
    wizd.clear();
    while(getline(cin, x) && x!="@END@"){
        int p=x.find(']');
        wizd[x.substr(0,p+1)]=x.substr(p+2);
        wizd[x.substr(p+2)]=x.substr(0,p+1);
    }
    int n;
    cin>>n;
    getchar();
    for(int i=0;i<n;i++){
        string lookup;
        getline(cin,lookup);
        if(wizd[lookup]=="") cout<<"what?"<<endl;
        else {
            string o=wizd[lookup];
            if(o[0]=='['){
                cout<<o.substr(1,o.find(']')-1)<<endl;
            }
            else cout<<o<<endl;
        }
    }
}

全部评论

相关推荐

挥毫自在:想白嫖你呢
点赞 评论 收藏
分享
包行:平时怎么刷算法题的哇,字节的手撕听说都很难
字节跳动工作体验
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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