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.");
}
}
}

POJ 1250 Tanning Salon的更多相关文章

  1. POJ 题目分类(转载)

    Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...

  2. (转)POJ题目分类

    初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推. ...

  3. poj分类

    初期: 一.基本算法:      (1)枚举. (poj1753,poj2965)      (2)贪心(poj1328,poj2109,poj2586)      (3)递归和分治法.      ( ...

  4. poj 题目分类(1)

    poj 题目分类 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K--0.50K:中短代码:0.51K--1.00K:中等代码量:1.01K--2.00K:长代码:2.01 ...

  5. POJ题目分类(按初级\中级\高级等分类,有助于大家根据个人情况学习)

    本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算 ...

  6. POJ题目分类(转)

    初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推. ...

  7. POJ题目细究

    acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  102 ...

  8. POJ题目(转)

    http://www.cnblogs.com/kuangbin/archive/2011/07/29/2120667.html 初期:一.基本算法:     (1)枚举. (poj1753,poj29 ...

  9. [POJ题目分类][转]

    Hint:补补基础... 初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治 ...

随机推荐

  1. 开始学习<p>标签,添加段落

    如果想在网页上显示文章,这时就需要<p>标签了,把文章的段落放到<p>标签中. 语法: <p>段落文本</p> 注意一段文字一个<p>标签, ...

  2. 重新开始学习javase_多态(动态绑定、推迟绑定或者运行期绑定)

    一,谈向上转换,或者上溯造型 什么是向上转换(上溯造型),一句话就是父类的引用指向子类的对象.或者把子类的对象当作父类来用 为什么要进行向上转换?我们先看一个例子吧! @Test public voi ...

  3. QT实现单个EXE文件

    有时候发布用Qt写的软件是件令人烦恼的事情,明明发布的只是一个简单功能的小软件,非得再附上一堆超大的动态链接库,实在让人觉得汗颜 . 在可执行文件单文件化方面,有多种方法.常用的是编译并使用静态 Qt ...

  4. 安装SVN及实现nginx web同步更新需要在WDCP一键安装包的基础上

    一.安装 1.查看是否安装cvs rpm -qa | grep subversion 2.安装 yum install subversion 3.测试是否安装成功 /usr/bin/svnserve ...

  5. MPICH2在两台Ubuntu上安装

    本文在经过大量的实验终于不负众望成功的在两台Ubuntu 12.04上部署MPI的一个小型集群,MPICH2所用版本为mpich2-1.4.1,下载地址:http://www.mcs.anl.gov/ ...

  6. mysql的limit经典用法及优化

    用法一   SELECT `keyword_rank`.* FROM `keyword_rank` WHERE (advertiserid='59') LIMIT 2 OFFSET 1;   比如这个 ...

  7. jQuery自带的一些常用方法总结

    jQuery自带的一些常用方法总结 这篇文章主要介绍了jQuery自带的一些常用方法总结,包括$.trim .$.contains.$.each.$.map.$.inArray.$.extend等,需 ...

  8. UVA 11722 几何概型

    第六周A题 - 几何概型 Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu   Descriptio ...

  9. Swift互用性:与 C的API交互(Swift 2.0版)-b

    节包含内容: 基本数据类型(Primitive Types) 枚举(Enumerations) 指针(Pointer) 全局常量(Global Constants) 预处理指令(Preprocesso ...

  10. poj 2983Is the Information Reliable?

    http://poj.org/problem?id=2983 #include<cstdio> #include<cstring> #include<algorithm& ...