您的位置:首页 > 其它

Tautology(POJ 3295编译原理)

2013-08-07 15:53 399 查看
~题目链接~

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
)
{
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;
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: