Follows 673.c (Total 32 lines):

/* @JUDGE_ID:4461XX 673 C */
/* A */
#include<stdio.h>
void main( void )
{
        char arr[130] , stack[130] ;
        int num , head , i , j , yes ;
        scanf( "%d\n" , &num ) ;
        for( ; num>0 ; num-- ){
                gets( arr ) ;
                for( head=i=0 , yes=1 ; arr[i] && yes ; i++ ){
                        if( arr[i] == ')' ){
                                if( head ){
                                        head-- ;
                                        if( stack[head] != '(' ) yes = 0 ;
                                }
                                else yes=0 ;
                        }
                        else if( arr[i] == ']' ){
                                head-- ;
                                if( stack[head] != '[' ) yes = 0 ;
                        }
                        else if( arr[i] == '(' || arr[i] == '[' )
                                stack[head++] = arr[i] ;
                        else yes = 0 ;
                }
                if( yes )
                        if( !head ) puts( "Yes" ) ;
                        else puts( "No" ) ;
                else puts( "No" ) ;
        }
}

Back to statistics
Ya-Lin Huang (C)
huangyl@gmail.com