| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
新人一次AC,C++代码,抛砖引玉堆栈解法
#include<iostream>
#include<string.h>
#include<cmath>
using namespace std;
int main()
{
char a[250];
int b[6];
gets(a);
int l;
while (a[0]!='0')
{
int p=1;
for (int i=1;i<=5;i++) b[i]=0;
for (int i=0;i<=32&&p;i++)
{
int i1=i;
for (int j=0;j<5;j++)
{
b[j]=i1%2;
i1=i1/2;
}
l=strlen(a);
int ls=0;
int c[100];
for (int j=l-1;j>=0;j--)
{
if (a[j]>='p'&&a[j]<='t')
{
ls++;
c[ls]=b[int(a[j]-'p')];
}
if (a[j]=='N') c[ls]=!c[ls];
if (a[j]=='K')
{
ls--;
c[ls]=(c[ls]&&c[ls+1]);
}
if (a[j]=='A')
{
ls--;
c[ls]=(c[ls]||c[ls+1]);
}
if (a[j]=='E')
{
ls--;
c[ls]=(c[ls]==c[ls+1]);
}
if (a[j]=='C')
{
ls--;
c[ls]=((!c[ls])||c[ls+1]);
}
}
if (!c[1]) p=0;
}
if (p) cout<<"tautology\n";
else cout<<"not\n";
gets(a);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator