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

我写的这个代码,照样输出为1,同样wa

Posted by scuttemp at 2009-04-05 16:53:09 on Problem 1250
In Reply To:Re:如果输入为:1 ABCCAB时,输出应为1,而不是2;我WA了一次才发现的 Posted by:PengPeng at 2005-12-05 13:07:15
我写的这个代码,照样输出为1,同样wa

#include<iostream>
using namespace std;

int beds ;
char salon[25];
bool wait[26];
bool newer[26];

void sol()
{
	int len = strlen(salon);
	int left = 0 , lb = beds;
	for ( int  i = 0 ; i < len ; ++ i )
	{
		if ( newer[salon[i] - 'A'] == false )	//新来的
		{
			if ( lb > 0 )
			{
				-- lb ;								//霸着床位
			}
			else									//进入等待队列,如果出来时还没有床位,那就离开了
			{
				wait[salon[i] - 'A'] = true;
			}
			newer[salon[i] - 'A'] = true;				//已不是新来的
		}
		else
		{
			if ( wait[salon[i] - 'A' ] == false )		//曾是霸着位的主儿
			{
				++ lb;
			}
			else if ( wait[salon[i] - 'A' ] == true && lb > 0 )		//如果在等待而且有床位了
			{
				wait[salon[i] - 'A'] = false;
				-- lb;
			}
			else												//等不及了,走了
			{
				++ left ;
				wait[salon[i] - 'A'] = false;
			}
		}
	}

	if (left)
		printf("%d customer(s) walked away.\n" , left);
	else
		printf("All customers tanned successfully.\n");
}

int main()
{
	while( scanf("%d",&beds) , beds != 0 )
	{
		memset(newer,0,sizeof(newer));
		memset(wait,0,sizeof(wait));
		scanf("%s",salon);
		sol();
	}
	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