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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
| #include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
vector<string> split(const string &str, char delim) {
vector<string> res;
size_t current = 0, found;
while((found = str.find_first_of(delim, current)) != string::npos) {
res.push_back(string(str, current, found - current));
current = found + 1;
}
res.push_back(string(str, current, str.size() - current));
return res;
}
int formula(string& s, int& i) {
if(s[i] == '(') {
i++;
int val = formula(s, i);
char op = s[i];
if(s[i] == '-' && s[i+1] == '>') {
i++;
op = s[i];
}
i++;
int val2 = formula(s, i);
int ret = 0;
if(op == '+') {
if(val || val2) ret = 1;
else ret = 0;
} else if(op == '*') {
if(val && val2) ret = 1;
else ret = 0;
} else if(op == '>') {
if(!val) ret = 1;
else if(val2) ret = 1;
else ret = 0;
}
i++;
return ret;
} else if(isdigit(s[i])) {
int ret = s[i] - '0';
i++;
return ret;
} else if(s[i] == '-') {
i++;
int ret = formula(s, i);
if(ret == 0) return 1;
else return 0;
}
}
bool used[30];
int main() {
string s;
while(cin >> s) {
if(s == "#") break;
vector<string> ret = split(s, '=');
string s1 = ret[0];
string s2 = ret[1];
bool flag = true;
rep(i, 1<<11) {
memset(used, 0, sizeof(used));
rep(j, 11) {
if(i & (1<<j)) used[j] = true;
}
string t1 = s1, t2 = s2;
rep(j, t1.size()) {
if('a' <= t1[j] && t1[j] <= 'k') {
if(used[t1[j] - 'a']) t1[j] = 'T';
else t1[j] = 'F';
}
if(t1[j] == 'T') t1[j] = '1';
if(t1[j] == 'F') t1[j] = '0';
}
rep(j, t2.size()) {
if('a' <= t2[j] && t2[j] <= 'k') {
if(used[t2[j] - 'a']) t2[j] = 'T';
else t2[j] = 'F';
}
if(t2[j] == 'T') t2[j] = '1';
if(t2[j] == 'F') t2[j] = '0';
}
int j = 0, k = 0;
int f1 = formula(t1, j);
int f2 = formula(t2, k);
if(f1 == f2) continue;
flag = false;
break;
}
if(flag) cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
}
|