| ||||||||||
| 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 | |||||||||
Re:细节啊细节啊,写N的时候忘记讨论了,把N后面是KANCE的情况忽略了。。。细节细节啊!In Reply To:细节啊细节啊,写N的时候忘记讨论了,把N后面是KANCE的情况忽略了。。。细节细节啊! Posted by:symons at 2014-02-18 19:11:05 #include <stdio.h>
#include <string.h>
char tmp[1000000+10];
int p,q,r,s,t;
int l;
struct res{
int pos;
int res;
};
struct res haha(int begin){
char SIGN=tmp[begin];
struct res rr;
int a,b;
int pos;
struct res tt;
if(SIGN=='N'){
pos=begin+1;
if(tmp[pos]=='0'||tmp[pos]=='1'){
a=tmp[pos]-'0';
pos=pos;
}else{
tt=haha(pos);
a=tt.res;
pos=tt.pos;
}
if(a==0) rr.res=1;
else rr.res=0;
rr.pos=pos;
return rr;
}
else{
pos=begin+1;
if(tmp[pos]=='0'||tmp[pos]=='1'){
a=tmp[pos]-'0';
pos=pos+1;
}else{
tt=haha(pos);
a=tt.res;
pos=tt.pos+1;
}
if(tmp[pos]=='0'||tmp[pos]=='1'){
b=tmp[pos]-'0';
}else{
tt=haha(pos);
b=tt.res;
pos=tt.pos;
}
}
rr.pos=pos;
if(SIGN=='K'){
if(a*b>0)
rr.res=1;
else rr.res=0;
}else if(SIGN=='A'){
if(a+b>0) rr.res=1;
else rr.res=0;
}else if(SIGN=='C'){
if(a<=b) rr.res=1;
else rr.res=0;
}else if(SIGN=='E'){
if(a==b) rr.res=1;
else rr.res=0;
}
return rr;
}
int iff(char str[]){
l=strlen(str);
int i;
struct res sum;
for(p=0;p<=1;++p)
for(q=0;q<=1;++q)
for(r=0;r<=1;++r)
for(s=0;s<=1;++s)
for(t=0;t<=1;++t){
strcpy(tmp,str);
for(i=0;i<l;++i){
if(tmp[i]=='p') tmp[i]='0'+p;
else if(tmp[i]=='q') tmp[i]='0'+q;
else if(tmp[i]=='r') tmp[i]='0'+r;
else if(tmp[i]=='s') tmp[i]='0'+s;
else if(tmp[i]=='t') tmp[i]='0'+t;
}
sum=haha(0);
if(sum.res==0) return 0;
}
return 1;
}
int main(){
char str[1000000+10];
int rres;
while(~scanf("%s",str)){
if(str[0]=='0') break;
if(strlen(str)==1){ printf("not\n");continue;}
rres=iff(str);
if(rres==1) printf("tautology\n");
else printf("not\n");
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator