Follows 112.c (Total 51 lines):

/* @JUDGE_ID:4461XX 112 C */
/* A */
#include<stdio.h>
int wait[10000] , n , yes ;
void count( int where )
{
	int i , ans ;
	for( ans=i=0 ; i<where ; i++ ) ans += wait[i] ;
	if( ans == n ) yes = 1 ;
}
void recursive( int level , int direct )
{
	int num ;
	char ch ;
	if( scanf( "%d" , &num ) != 1 ){
		if( direct==2 && !wait[level] ){
			wait[level] = -1 ;
			count( level ) ;
		}
		if( direct == 1 ) wait[level] = 0 ;
		return ;
	}
	else wait[level] = num ;
	while( scanf( "%c" , &ch ) == 1 ) if( ch == '(' ) break ;
	recursive( level+1 , 1 ) ;
	while( scanf( "%c" , &ch ) == 1 ) if( ch == ')' ) break ;
	while( scanf( "%c" , &ch ) == 1 ) if( ch == '(' ) break ;
	recursive( level+1 , 2 ) ;
	wait[level] = -1 ;
	while( scanf( "%c" , &ch ) == 1 ) if( ch == ')' ) break ;
}
void main( void )
{
	char ch ;
	int i ;
/*	freopen( "C:\\windows\\desktop\\112.in" , "r" , stdin ) ;*/
	while( scanf( "%d" , &n ) == 1 ){
		yes = 0 ;
		for( i=0 ; i<10000 ; i++ ) wait[i] = -1 ;
		while( scanf( "%c" , &ch ) == 1 )
			if( ch == '(' ){
				recursive( 0 , 0 ) ;
				while( scanf( "%c" , &ch ) == 1 )
					if( ch == ')' ) break ;
				break ;
			}
		if( yes ) puts( "yes" ) ;
		else puts( "no" ) ;
		scanf( "\n" ) ;
	}
}

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