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

一次AC,帅气!

Posted by et1239063237 at 2012-08-01 23:46:31 on Problem 1250
#include<iostream>
#include<string>

using namespace std;

int main()
{
	int salon; //salon数量
	int left;  //当前剩余 salon 数量
	int away;  //走掉的客人
	string customer;  //客人序列

	bool alph[26]={0};//表示客人是否在 salon 中

	int i;//计数器
	int len;//customer字符串长度

	while(1)
	{
		cin>>salon;
		if(salon==0)
			break;

		cin>>customer;

		left=salon;
		away=0;
		len=customer.length();
		for(i=0;i<len;i++)
		{
			if(alph[customer[i]-65]==false)
			{
				left--;
				if(left<0)
					away++;
				alph[customer[i]-65]=true;
				continue;
			}
			else if(alph[customer[i]-65]==true)
			{
				left++;
				alph[customer[i]-65]=false;
				continue;
			}
		}

		if(away==0)
			cout<<"All customers tanned successfully."<<endl;
		else
			cout<<away<<" customer(s) walked away."<<endl;
	}

	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