-
Notifications
You must be signed in to change notification settings - Fork 0
/
POJ3295.cpp
71 lines (69 loc) · 1.96 KB
/
POJ3295.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
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
#include <iostream>
#include <stack>
#include <string>
using namespace std;
bool cal(string str, char var) //Calculate the Prefix
{
stack<bool> num;
bool val_l, val_r;
for(int i = str.size() - 1; i >= 0; i--)
{
if(str[i] >= 'p' && str[i] <= 't')
num.push(var & (1 << (str[i] - 'p')));
else
switch(str[i])
{
case 'K':
val_r = num.top();
num.pop();
val_l = num.top();
num.pop();
num.push(val_l && val_r);
break;
case 'A':
val_r = num.top();
num.pop();
val_l = num.top();
num.pop();
num.push(val_l || val_r);
break;
case 'N':
val_r = num.top();
num.pop();
num.push(!val_r);
break;
case 'C':
val_r = num.top();
num.pop();
val_l = num.top();
num.pop();
num.push(!val_l || (val_l && val_r));
break;
case 'E':
val_r = num.top();
num.pop();
val_l = num.top();
num.pop();
num.push(val_l == val_r);
break;
}
}
return num.top();
}
int main(void)
{
string input;
char var; //Store the value of "p q r s t" in BIT0~4
while(1)
{
cin >> input;
if(input[0] == '0')
break;
for(var = 0; var < 1 << 6; var++)
if(!cal(input, var))break;
if(var == 1 << 6)
cout << "tautology" << endl;
else
cout << "not" << endl;
}
}