-
Notifications
You must be signed in to change notification settings - Fork 13
/
logic-gates.cpp
32 lines (27 loc) · 994 Bytes
/
logic-gates.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
#include <bits/stdc++.h>
typedef std::string SIG;
int main()
{
int n, m;
std::string so, s1, s2, op, val;
std::unordered_map<SIG, SIG> cache;
std::unordered_map<SIG, std::function<bool(bool, bool)>> ops =
{
{"AND", [](bool a, bool b){return a & b; }},
{"OR", [](bool a, bool b){return a | b; }},
{"XOR", [](bool a, bool b){return a ^ b; }},
{"NAND", [](bool a, bool b){return !(a & b); }},
{"NOR", [](bool a, bool b){return !(a | b); }},
{"NXOR", [](bool a, bool b){return !(a ^ b); }},
};
std::cin >> n >> m;
for (int i = 0; i < n; ++i)
std::cin >> so >> cache[so];
for (int i = 0; i < m; ++i) {
std::cin >> so >> op >> s1 >> s2;
std::cout << so << " ";
for (int j = 0; j < cache[s1].size(); ++j)
std::cout << (ops[op](cache[s1][j] == '-', cache[s2][j] == '-') ? '-' : '_');
std::cout << '\n';
}
}