zoukankan      html  css  js  c++  java
  • 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.");
    		}
    	}
    }



  • 相关阅读:
    科大奥瑞大物实验-A类不确定度计算器 代码
    在手机和电脑间双向加密传输文件 —— Windows 安装 Kde Connect
    Leetcode 寻找两个有序数组的中位数
    树莓派3B安装 Arch Linux ARM
    从零开始编译安装 Extcalc
    Oracle, PostgreSQl, MySQL针对INSERT时可能唯一键重复的SQL
    如何从Oracle, MySql, PostgreSQL的PreparedStatement获得所执行的sql语句?
    PostgreSQL报错:当前事务被终止,命令被忽略,直到事务块结束
    PostgreSQL对GROUP BY子句使用常量的特殊限制
    一种用JDBC实现批量查询的巧妙方法
  • 原文地址:https://www.cnblogs.com/dyllove98/p/3225833.html
Copyright © 2011-2022 走看看