Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

第一次贴自己的代码~~~写了3天,在19次错误后终于A过去了...还是自己的技术渣啊...

Posted by lianai911 at 2013-12-04 20:48:49 on Problem 3295
# 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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator