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. Objective-C 类,函数调用

    // // main.m // L02HelloObjC // // Created by JinXin on 15/11/25. // Copyright © 2015年 JinXin. All r ...

  2. Hibernate 多对多关联Demo

    以学生[Student ]与课程[Course ]之间的关系为例: //Course .java public class Course implements Serializable { priva ...

  3. 你好,C++(9)坐216路公交车去买3.5元一斤的西红柿——C++中如何表达各种数值数据 3.3 数值数据类型

    3.3  数值数据类型 从每天早上睁开眼睛的那一刻开始,我们几乎每时每刻都在与数字打交道:从闹钟上的6点30分,到上班坐的216路公共汽车:从新闻中说的房价跌到了100元每平米到回家买菜时的西红柿3. ...

  4. nuc900 nand flash mtd 驱动

    nuc900 nand flash mtd 驱动,请参考! /* * Copyright © 2009 Nuvoton technology corporation. * * Wan ZongShun ...

  5. JQuery语法总结和注意事项

    1.关于页面元素的引用 通过jquery的$()引用元素包括通过id.class.元素名以及元素的层级关系及dom或者xpath条件等方法,且返回的对象为jquery对象(集合对象),不能直接调用do ...

  6. Javascript中回调函数的学习笔记

    function a_b(kkis){ document.body.style.background ='red'; kkis(); } function fli(){ alert('######## ...

  7. ucenter 通信原理

    1.用户登录discuz,通过logging.php文件中的函数uc_user_login对post过来的数据进行验证,也就是对username和password进行验证. 2.如果验证成功,将调用位 ...

  8. Delphi笔记(GL_Scene四轴飞行器模型)

    有了前的一篇做铺垫,已经简单的说了GL_Scene的下载安装和一个简单的实例制作.现在就要开始制作一个3D的模型了,具体的步骤就不再这里多说了,直接上图和代码吧! [第一版]先看一下最开始的版本吧,比 ...

  9. JVM笔记-逃逸分析

    参考: http://www.iteye.com/topic/473355http://blog.sina.com.cn/s/blog_4b6047bc01000avq.html 什么是逃逸分析(Es ...

  10. Scut:运行测试服务器

    在大致过了一遍Scut的底层结构(其实只是对各个组件有了一个初步印象而已),现在开始尝试搭建“口袋天界”的Scut服务端. 1. 设置外部启动项 项目属性 -- 调试 -- 启动外部程序 -- 项目根 ...