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

小心这种东西:!!!!!!!!!!!!!!!!!!!!!!F

Posted by 00448264 at 2005-05-18 17:29:11 on Problem 2106
In Reply To:请教:这样是不是因为输入死循环引起TLE?? Posted by:WZPWZPWZP at 2005-05-18 17:13:54
> #include <stdio.h>
> #include <string.h>
> 
> 
> char	s[200];
> bool	get(int i,int j)
> {
> 	int		x , y , l;
> 
> 	bool	g , f , rev = false;
> 	char	op;
> 
> 	x = i;
> 	if( s[x] == '!' ){rev = true ;x++;}
> 	
> 	if( s[x] == 'V' ){g = true;y=x;}
> 	else if( s[x] == 'F' ){g = false;y=x;}
> 	else if( s[x] == '(')
> 	{
> 		for( l = 1 ,y = x +1 ; y <= j ; y++ )
> 		{
> 			if( s[y] == '(')l++;
> 			else if( s[y] == ')' ){l--;if(l==0)break;}
> 		}
> 
> 		g = get(x+1,y-1);
> 	}
> 	
> 	if( rev == true ) {g = !g;rev = false;}
> 
> 	for( x = y +1 ; x <= j ; )
> 	{
> 		op = s[x++];
> 		if( s[x] == '!' ){rev = true ;x++;}
> 		
> 		if( s[x] == 'V' ){f = true;y=x;}
> 		else if( s[x] == 'F' ){f = false;y=x;}
> 		else if( s[x] == '(')
> 		{
> 			for( l = 1 ,y = x +1 ; y <= j ; y++ )
> 				if( s[y] == '(')l++;
> 				else if( s[y] == ')' ){l--;if(l==0)break;}
> 
> 			f = get(x+1,y-1);
> 		}
> 
> 		if( rev == true ) {f = !f;rev = false;}
> 		if( op == '&' ) g = g & f;
> 		else g = g | f;
> 		x = y +1 ;
> 	}
> 	return g;
> }
> 
> 
> int		main()
> {
> 	int		 i , t = 1 ;
> 	char	c;
> 	//FILE*	f = fopen("in.txt","r");
> 
> 	for(  c = getchar() ; ;  c = getchar())
> 	{
> 		if( c == EOF )return 0;
> 
> 		i = 0;
> 		while( c != '\n' )
> 		{
> 			switch(c)
> 			{
> 			case ' ':break;
> 			default :s[i++] = c;
> 			}
> 			c = getchar();
> 			
> 		}
> 		s[i] = 0;
> 		if( strlen(s) != 0 ){printf("Expression %d: %c\n",t++,(get(0,strlen(s)-1)?'V':'F'));}
> 		
> 	}
> 
> }
> 
> 
> 
> 	

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