看到的时候完全没有想到位操作。。。还是差好多
#include <iostream>
#include <stdio.h>#include <string.h>
#include <stack>
using namespace std;
int main()
{
int p[] = {1,0};
int q[] = {1,0};
int r[] = {1,0};
int s[] = {1,0};
int t[] = {1,0};
char str[110];
stack <int> sta;
while(scanf("%s",str), str[0] != '0')
{
bool flag = true;
int len = strlen(str);
for( int i1 = 0; i1 <= 1; i1++)
{
for( int i2 = 0; i2 <= 1; i2++)
{
for( int i3 = 0; i3 <= 1; i3++)
{
for( int i4 = 0; i4 <= 1; i4++)
{
for( int i5 = 0; i5 <= 1; i5++)
{
for( int i = len - 1; i >= 0; i--)
{
if(str[i] >= 'Z')
{
if(str[i] == 'p')
sta.push(q[i1]);
else if(str[i] == 'q')
sta.push(q[i2]);
else if(str[i] == 'r')
sta.push(q[i3]);
else if(str[i] == 's')
sta.push(q[i4]);
else if(str[i] == 't')
sta.push(q[i5]);
}
else if(str[i] == 'N')
{
int n = sta.top();
sta.pop();
sta.push(!n);
}
else if(str[i] == 'A')
{
int n = sta.top();
sta.pop();
int m = sta.top();
sta.pop();
int temp =( n || m);
sta.push(temp);
}
else if(str[i] == 'K')
{
int n = sta.top();
sta.pop();
int m = sta.top();
sta.pop();
int temp = (n && m);
sta.push(temp);
}
else if(str[i] == 'E')
{
int n = sta.top();
sta.pop();
int m = sta.top();
sta.pop();
int temp = (n == m ? 1 : 0);
sta.push(temp);
}
else if(str[i] == 'C')
{
int n = sta.top();
sta.pop();
int m = sta.top();
sta.pop();
int temp = (!m || n);
sta.push(temp);
}
}
if(sta.top() == 0)
{
flag = false;
goto L;
}
}
}
}
}
}
L:
if(flag)
cout<<"tautology"<<endl;
else
cout<<"not"<<endl;
}
return 0;
}