-
Notifications
You must be signed in to change notification settings - Fork 104
/
10.8.cpp
44 lines (40 loc) · 1.2 KB
/
10.8.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* 题目名称:魔咒词典
* 题目来源:浙江大学复试上机题
* 题目链接:http://t.cn/AiCufczt
* 代码作者:杨泽邦(炉灰)
*/
#include <iostream>
#include <cstdio>
#include <string>
#include <map>
using namespace std;
map<string, string> dictionary;
int main() {
string str;
while (getline(cin, str)) {
if (str == "@END@") {
break;
}
int position = str.find(']'); //分界点
string key = str.substr(0, position + 1); //魔咒
string value = str.substr(position + 2); //功能
dictionary[key] = value;
dictionary[value] = key;
}
int n;
scanf("%d", &n);
getchar(); //吃掉回车
while (n--) {
string 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;
}