现在的位置: 首页 > 综合 > 正文

poj3295

2019年11月09日 ⁄ 综合 ⁄ 共 1036字 ⁄ 字号 评论关闭
#include<iostream>
#include<cstring>
#include<stack>
using namespace std;
int K(int w,int x)//各逻辑判断实现 
{
	if(w==1&&x==1)
	return 1;
	return 0;
}
int A(int w,int x)
{
	if(w==0&&x==0)
	return 0;
	return 1;
}
int N(int w)
{
	return !w;
}
int C(int w,int x)
{
	if(w==1&&x==0)
	return 0;
	return 1;
}
int E(int w,int x)
{
	if(w==x)
	return 1;
	return 0;
}
int judge(char *a)//暴力枚举 
{
	stack<int>s1;
	int i,n,p,q,r,s,t,temp1,temp2;
	n=strlen(a);
	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++)
	{
		for(i=n-1;i>-1;i--)
		{
			if(a[i]=='p')
			{
				s1.push(p);
			}
			else if(a[i]=='q')
			{
				s1.push(q);
			}
			else if(a[i]=='r')
			{
				s1.push(r);
			}
			else if(a[i]=='s')
			{
				s1.push(s);
			}
			else if(a[i]=='t')
			{
				s1.push(t);
			}
			else if(a[i]=='N')
			{
				temp1=s1.top();
				s1.pop();
				s1.push(N(temp1));
			}
			else
			{
				temp1=s1.top();
				s1.pop();
				temp2=s1.top();
				s1.pop();
				if(a[i]=='K')
				{
					s1.push(K(temp1,temp2));
				}
				else if(a[i]=='A')
				{
					s1.push(A(temp1,temp2));
				}
				else if(a[i]=='C')
				{
					s1.push(C(temp1,temp2));
				}
				else
				{
					s1.push(E(temp1,temp2));
				}
			}
		}
		temp1=s1.top();
		s1.pop();
		if(!temp1)
		return 0;
	}
	return 1;
}
int main()
{
	char a[100];
	while(scanf("%s",a)&&a[0]!='0')
	{
		if(judge(a))
		printf("tautology\n");
		else
		printf("not\n");
	}
}

【上篇】
【下篇】

抱歉!评论已关闭.