Tautology(POJ 3295编译原理)
~题目链接~
http://poj.org/problem?id=3295
输入
ApNp ApNq 0
结果
tautology not
1.要把p,q,r,s,t的所有取值都搜索一遍
2.'K' a&b; 'A' a||b; 'N' !a; 'C' !a||b;'E' a==b;
3.如果为永真式,输出tautology;否则 not
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int n,flag,p,q,r,s,t;
char str[100];
int reach()
{
n++;
switch(str[n])
{
case 'K':return reach()&reach();
case 'A':return reach()|reach();
case 'N':return !reach();
case 'C':return !reach()|reach();
case 'E':return reach()==reach();
case 'p':return p;
case 'q':return q;
case 'r':return r;
case 's':return s;
case 't':return t;
}
}
int main()
{
while(~scanf("%s",str) && str[0]!='0')
{
flag=0;
//32中取值情况
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++)
{
n=-1;
if(!reach())
flag=1;
}
if(flag)
printf("not\n");
else
printf("tautology\n");
}
return 0;
}
浙公网安备 33010602011771号