首页 > 其他 > 详细

浙江大学机试 魔咒词典 Easy

时间:2020-03-05 21:58:34      阅读:52      评论:0      收藏:0      [点我收藏+]

基本思想:

无;

 

关键点:

无;

 

#include<iostream>
#include<string>
#include<vector>
#include<map>
using namespace std;


int main() {
    int n;
    string s;
    map<string, string>spll2tell;
    map<string, string>tell2spell;
    while (getline(cin,s)){
        if (s == "@END@")
            break;
        int index=-1;
        for (int i = 0; i < s.size(); i++) {
            if (s[i] == ]) {
                index = i;
                break;
            }
        }
        string spll = s.substr(0, index+1);
        string tell = s.substr(index + 2, s.size() - (index + 2));
        //cout << spll << " " << tell << endl;
        spll2tell[spll] = tell;
        spll = s.substr(1, index - 1);
        tell2spell[tell] = spll;
    }
    cin >> n;
    getchar();
    for (int i = 0; i < n; i++) {
        getline(cin, s);
        if (spll2tell.find(s) != spll2tell.end()) {
            cout << spll2tell[s] << endl;
        }
        else if (tell2spell.find(s) != tell2spell.end()) {
            cout << tell2spell[s] << endl;
        }
        else {
            cout << "what?" << endl;
        }
    }
    return 0;
}

 

浙江大学机试 魔咒词典 Easy

原文:https://www.cnblogs.com/songlinxuan/p/12422760.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!