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

我的为什么死活WA 啊,哪位牛人帮我看下啊

Posted by tibelf at 2007-11-03 14:35:24 on Problem 3437
#include <iostream>
#include <string>
using namespace std ;
 
int main(){
	string a ;
	int test = 1 ;
	while( getline( cin , a) )
	{
		if( a == "#" )
			break ;
		if( a == "" )
		{
			printf( "Tree %d: 0 => 0\n" , test ) ;
			continue ;
		}
		int n = 0 , i = 0 ;
		int b[10002] , visit[10002];
		memset( b , 0 , sizeof(b) ) ;
		memset( visit , 0 , sizeof( visit ) ) ;
		int len = a.size () ;
		int max = 0  ;
		while ( i < len )
		{
			if( a[i] == 'd' )
			{
				n ++ ;
				visit[n] ++ ;
				if( n > max )
					max = n ;
			}
			if( a[i] == 'u')
				n -- ;	
			i ++ ;
		}
		int maxn = 0 ;
		i = 0 , n = 0  ;
		int k = 0 ;
		while( i < len )
		{
			if( a[i] == 'd' )
			{
				k ++ ;
				n ++ ;
				if( k > n )
				{
					n ++ ;
					k = n ;
				}
				b[n] = b[n -1] + 1 ;
				if( b[n] > maxn )
					maxn = b[n] ;
			}
			if( a[i] == 'u')
				n -- ;
			i ++ ;
		}
		printf( "Tree %d: %d => %d\n" , test ++ , max , maxn ) ;
	}
	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