-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtautology.cpp
127 lines (122 loc) · 2.77 KB
/
tautology.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
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
#include <iostream>
#include <stack>
#include <string>
using namespace std;
bool p, q, r, s, t;
bool temp0,temp1;
stack<char> WFF;
stack<int> w;
string st[101];
void check(int &n)
{
int i = 0;
while(i<st[n].size())
{
WFF.push(st[n][i]);
i++;
}
while(!WFF.empty())
{
char temp = WFF.top();
WFF.pop();
switch(temp)
{
case 112:
w.push(p);
break;
case 113:
w.push(q);
break;
case 114:
w.push(r);
break;
case 115:
w.push(s);
break;
case 116:
w.push(t);
break;
case 65://»òÔËËã
temp0 = w.top();
w.pop();
temp1 = w.top();
w.pop();
temp0 = temp0 || temp1;
w.push(temp0);
break;
case 75://ÓëÔËËã
temp0 = w.top();
w.pop();
temp1 = w.top();
w.pop();
temp0 = temp0 && temp1;
w.push(temp0);
break;
case 78://·ÇÔËËã
temp0 = w.top();
w.pop();
temp0 = !temp0;
w.push(temp0);
break;
case 67://implis
temp0 = w.top();
w.pop();
temp1 = w.top();
w.pop();
temp0 = (!temp0) || temp1;
w.push(temp0);
break;
case 69://equel
temp0 = w.top();
w.pop();
temp1 = w.top();
w.pop();
if(temp0==temp1)
w.push(1);
else
w.push(0);
break;
}
}
}
int main()
{
string ss = "0";
int j = 0;
getline(cin,st[j]);
while(st[j]!=ss)
{
j++;
getline(cin,st[j]);
}
bool checkl;
int k = 0;
start:while(k<100&&st[k]!="0")
{
for (int i = 0; i < 32; i++)
{
int n = i;
p = n % 2;
n = n / 2;
q = n % 2;
n = n / 2;
r = n % 2;
n = n / 2;
s = n % 2;
n = n / 2;
t = n % 2;
check(k);
checkl = w.top();
w.pop();
if (!checkl)
{
k++;
cout << "not\n";
goto start;
}
}
k++;
cout << "tautology\n";
}
return 0;
}