-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetaprogramming.cpp
More file actions
42 lines (41 loc) · 977 Bytes
/
Copy pathmetaprogramming.cpp
File metadata and controls
42 lines (41 loc) · 977 Bytes
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
#include <iostream>
#include <unordered_map>
#include <sstream>
#include <string>
using namespace std;
int main() {
unordered_map<string, int> dict;
string line;
while (getline(cin, line)) {
stringstream ss(line);
string cmd; ss >> cmd;
if (cmd == "define") {
string value_str; ss >> value_str; int value_int = stoi(value_str);
string word; ss >> word;
dict[word] = value_int;
}
else {
string a, opr, b; ss >> a >> opr >> b;
if (dict.find(a) == dict.end() || dict.find(b) == dict.end())
cout << "undefined" << '\n';
else if (opr == "<") {
if (dict[a] < dict[b])
cout << "true" << '\n';
else
cout << "false" << '\n';
}
else if (opr == "=") {
if (dict[a] == dict[b])
cout << "true" << '\n';
else
cout << "false" << '\n';
}
else if (opr == ">") {
if (dict[a] > dict[b])
cout << "true" << '\n';
else
cout << "false" << '\n';
}
}
}
}