| ||||||||||
| 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 | |||||||||
小心这种东西:!!!!!!!!!!!!!!!!!!!!!!FIn 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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator