# 14094: 【原4094】Tanning Salon

### 题目描述

author: MUA 原OJ链接：https://acm.sjtu.edu.cn/OnlineJudge-old/problem/4094

# 【问题描述】

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.

# 【输入要求】

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.

# 【输出要求】

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

# 【输入样例】

``````2 ABBAJJKZKZ
3 GACCBDDBAGEE
3 GACCBGDDBAEE
1 ABCBCA
0
``````

# 【输出样例】

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

# 【来源】

Mid-Central USA 2002

## FineArtz's solution

``````/* Tanning Salon */
#include <iostream>
#include <cstring>
using namespace std;

void solve(int n){
int a[27] = {0}, b[27] = {0};
char s[1000];
cin >> s;
int m = 0, ans = 0, len = strlen(s);
for (int i = 0; i < len; ++i){
char ch = s[i];
if (m < n){
if (a[ch - 'A'] == 0){
++m;
a[ch - 'A'] = 1;
}
else{
--m;
a[ch - 'A'] = 0;
}
}
else{
if (a[ch - 'A'] == 1){
--m;
a[ch - 'A'] = 0;
}
else if (b[ch - 'A'] == 0){
++ans;
b[ch - 'A'] = 1;
}
}
}
if (ans)
cout << ans << " customer(s) walked away." << endl;
else
cout << "All customers tanned successfully." << endl;
}

int main(){
int n;
cin >> n;
while (n != 0){
solve(n);
cin >> n;
}
return 0;
}
``````

## q4x3's solution

``````/**
* 模拟题
* 注意 顾客第一次没床位第二次也不会进来...
* 理解题意5555
**/
#include <iostream>
#include <cstring>

using namespace std;

int num, cnt, cur;
char cus[100];
int in[30], lef[30];

int main() {
while(1) {
scanf("%d", &num);
if(num == 0) break;
cnt = 0; cur = 0;
for(int i = 0;i < 30;++ i) {
in[i] = 0;
lef[i] = 0;
}
scanf("%s", cus);
for(int i = 0;i < strlen(cus);++ i) {
if(in[cus[i] - 'A']) {
in[cus[i] - 'A'] = 0;
-- cur;
} else {
if(cur < num) {
if(lef[cus[i] - 'A']) continue;
in[cus[i] - 'A'] = 1;
++ cur;
}
else {
if(! lef[cus[i] - 'A']) ++ cnt;
lef[cus[i] - 'A'] = 1;
}
}
}
if(cnt) printf("%d customer(s) walked away.\n", cnt);
else printf("All customers tanned successfully.\n");
}
}
``````

## victrid's solution

``````#include <cstdio>
#include <iostream>

using namespace std;
//Rewrite without STL
int check() {
int bednum      = 0;
int current     = 0;
scanf("%d", &bednum);
if (!bednum)
return -1;
int avail[1000] = {0};
getchar();
char process = getchar();
while (process != '\n') {
if (avail[process] == 0) {
avail[process] = 1;
current++;
if (current > bednum) {
current--;
avail[process] = 2;
}
} else {
if (avail[process] != 2)
current--;
avail[process] = 0;
}
process = getchar();
}
}
int main() {
int board[10000];
int bs      = 0;
int process = check();
while (process != -1) {
board[bs] = process;
bs++;
process = check();
}
for (int i = 0; i < bs; i++) {
if (board[i] != 0)
printf("%d customer(s) walked away.\n", board[i]);
else
printf("All customers tanned successfully.\n");
}
return 0;
}
``````