POJ 1250 Tanning Salon

Tanning Salon
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 6822   Accepted: 3686

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 ABBAJJKZKZ
3 GACCBDDBAGEE
3 GACCBGDDBAEE
1 ABCBCA
0

Sample Output

All customers tanned successfully.
1 customer(s) walked away.
All customers tanned successfully.
2 customer(s) walked away.
/*
* 大概意思就是,有n个位置,然后一个字符串,字符串中的每个字符代表一个人,字母相同的代表同一人,
* 第一次出现代表占一个位置(如果位置满了,客人直接走了)
* 第二次出现代表走了,把位置空出来,由于位置有限制,所以计算最后一共有几个人没位置走了
*
*/
import java.util.HashMap;
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
while(true){
int n=input.nextInt();
HashMap<Character,Boolean> map=new HashMap<Character,Boolean>();
if(n==0)
break;
String s=input.next();
int num=0;
for(int i=0;i<s.length();i++){
char a=s.charAt(i);
if(map.get(a)!=null){//代表第二次出现这个字母
if(map.get(a)==false){//代表他当时没有位置,所以不要让出位置
continue;
}
n++;
map.put(a, null);//让出位置
}
else if(n>0){
map.put(a, true);//有位置,进入占个位置
n--;
}
else{
num++;
map.put(a, false);//没位置了,走人,num++,记录走了几个人
}
}
if(num==0)
System.out.println("All customers tanned successfully.");
else
System.out.println(num+" customer(s) walked away.");
}
}
}
上一篇:win10 x64中 windbg x64 安装配置符号库


下一篇:WinDbg的安装、配置和功能