题目链接:点击打开链接
题目大意是根据给出的运算法则,判断式子是否真,变量有5个,枚举所有可能值,其中有假就为假。
//164K 0MS
//C++ 1899B
#include <cstdio>
#include <cstring>
#define abs(i) (i>=0?i:-i)
int p,q,r,s,t;
char str[111];
int st[111];
void x()
{
int top=0;
int len=strlen(str);
for(int i=len-1;i>=0;i--)
{
if(str[i]=='p') st[top++]=p;
else if(str[i]=='q') st[top++]=q;
else if(str[i]=='r') st[top++]=r;
else if(str[i]=='s') st[top++]=s;
else if(str[i]=='t') st[top++]=t;
else if(str[i]=='K')
{
int t1=st[--top];
int t2=st[--top];
if(t1&&t2)
st[top++]=1;
else
st[top++]=0;
}
else if(str[i]=='A')
{
int t1=st[--top];
int t2=st[--top];
if(t1||t2)
st[top++]=1;
else
st[top++]=0;
}
else if(str[i]=='C')
{
int t1=st[--top];
int t2=st[--top];
if(t1==1&&t2==0)
st[top++]=0;
else
st[top++]=1;
}
else if(str[i]=='E')
{
int t1=st[--top];
int t2=st[--top];
if(t1==t2)
st[top++]=1;
else
st[top++]=0;
}
else if(str[i]=='N')
{
int t1=st[--top]-1;
st[top++]=abs(t1);
}
}
}
bool f()
{
for(p=0;p<2;p++)
for(q=0;q<2;q++)
for(r=0;r<2;r++)
for(s=0;s<2;s++)
for(t=0;t<2;t++)
{
x();
if(st[0]==0)
return false;
}
return true;
}
int main()
{
while(~scanf("%s",str)&&strcmp(str,"0"))
{
if(f())
{
printf("tautology\n");
}
else
{
printf("not\n");
}
}
return 0;
}