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 |
第一次贴自己的代码~~~写了3天,在19次错误后终于A过去了...还是自己的技术渣啊...# include<stdio.h> # include<string.h> # include<stdlib.h> char wff[210]; int stack[210]; int caller(char c,int w,int x) { switch(c) { case'K': return w & x; case'A': return w | x; case'C': return !w | x; case'E': return w == x; } } int getv(char c,int p,int q,int r,int s,int t) { switch (c) { case 'p': return p; case 'q': return q; case 'r': return r; case 's': return s; case 't': return t; } } int main() { // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); int i,len,top,state; int p,q,r,s,t; memset(wff,0,sizeof(wff)); memset(stack,0,sizeof(stack)); while(scanf("%s",wff) && wff[0]!='0') { len = strlen(wff); state = 1; 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++) { top = 1; memset(stack,0,sizeof(stack)); for(i=len-1;i>=0;i--) { if(wff[i]>='p' && wff[i]<='t') stack[top++] = getv(wff[i],p,q,r,s,t); else if(wff[i]=='K'|| wff[i]=='A'|| wff[i]=='C'|| wff[i]=='E') { stack[top-2] = caller(wff[i],stack[top-1],stack[top-2]); top--; } else if(wff[i]=='N') { stack[top-1] = (1 - stack[top-1]); } } if(!stack[top-1]) { state = 0; break; } } } } } } if(state==1) printf("tautology\n"); else printf("not\n"); memset(wff,0,sizeof(wff)); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator