0%

北大 acm 1250 Tanning Salon 解题报告

Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3652 Accepted: 2065

Description

Tan Your Hide, Inc., owns several coin-operated tanning salons. Research has shown that if a customer arrives and there are no beds available, the customer will turn around and leave, thus costing the company a sale. Your task is to write a program that tells the company how many customers left without tanning.

Input

The input consists of data for one or more salons, followed by a line containing the number 0 that signals the end of the input. Data for each salon is a single line containing a positive integer, representing the number of tanning beds in the salon, followed by a space, followed by a sequence of uppercase letters. Letters in the sequence occur in pairs. The first occurrence indicates the arrival of a customer, the second indicates the departure of that same customer. No letter will occur in more than one pair. Customers who leave without tanning always depart before customers who are currently tanning. There are at most 20 beds per salon.

Output

For each salon, output a sentence telling how many customers, if any, walked away. Use the exact format shown below.

Sample Input

2 ABBAJJKZKZ3 GACCBDDBAGEE3 GACCBGDDBAEE1 ABCBCA0

Sample Output

All customers tanned successfully.1 customer(s) walked away.All customers tanned successfully.2 customer(s) walked away.

题意:晒黑沙龙里面有bednumber个床位,所以做多容纳bednumber个顾客,bednumber个 位置全部满了,则后来的顾客就流失,问一共流失了几个顾客

代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>

using namespace std;

int main()
{
int current,leave,bednumber; //current代表目前用了几个位置,leave代表流失的人数,bednumber代表床铺的个数
char people[100],beds[21];//people代表总的人数,beds[i]代表i个床铺上的人是谁
int i,j,k,stay;

while(cin>>bednumber&&bednumber)
{
cin>>people;
leave=0;
i=0;
current=0;

while(i<strlen(people))
{
stay=0;
for(j=0;j<current;j++)
if(beds[j]==people[i])//检查是否已经在沙龙里,如果是则表示离开
{
for(k=j;k<current-1;k++) //离开之后每个人往前挪一个位置
beds[k]=beds[k+1];

stay=1; //1表明有人离开
current--; //目前用了的床位减1
break;
}

if(stay==0) //0表示不再沙龙里
{
if(current<bednumber)
{
beds[current]=people[i];
current++;
}//如果位置未满则可以加人
else
leave++; //否则位置满了,流失的人数加1
}
i++;
}

if(leave==0)
cout<<"All customers tanned successfully."<<endl;
else
cout<<leave/2<<" customer(s) walked away."<<endl;
}
return 0;
}
谢谢您的打赏,我的大英雄 ^_^
Thank you for your generosity, my big hero ^_^

更多内容请关注公众号「西小玛」