| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
一次AC,帅气!#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator