poj-1250Tanning Salon
来源:互联网 发布:清理mac系统垃圾软件 编辑:程序博客网 时间:2024/05/16 15:49
Tanning Salon
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 6828 Accepted: 3689
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 ABBAJJKZKZ3 GACCBDDBAGEE3 GACCBGDDBAEE1 ABCBCA0
Sample Output
All customers tanned successfully.1 customer(s) walked away.All customers tanned successfully.2 customer(s) walked away.
Source
Mid-Central USA 2002
代码:
import java.util.LinkedList;import java.util.Scanner;public class Main {/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubScanner input=new Scanner(System.in);while(input.hasNext()){int n=input.nextInt();if(n==0)break;String str=input.next();LinkedList<Character> a=new LinkedList<Character>();LinkedList<Character> b=new LinkedList<Character>();for(int i=0;i<str.length();i++){char c=str.charAt(i);if(b.indexOf(c)==-1){ if(a.indexOf(c)!=-1) a.remove(a.indexOf(c)); else{ if(a.size()<n) a.add(c); else b.add(c);}}}if(b.size()==0) System.out.println("All customers tanned successfully.");elseSystem.out.println(b.size()+" customer(s) walked away.");}}}
- POJ-1250-Tanning Salon
- POJ 1250 Tanning Salon
- poj 1250(Tanning Salon)
- poj 1250 Tanning Salon
- POJ 1250 tanning salon
- POJ 1250 Tanning Salon
- poj-1250Tanning Salon
- poj 1250 Tanning Salon
- poj 1250 Tanning Salon
- POJ 1250 Tanning Salon
- poj 1250 Tanning Salon(模拟)
- POJ 1250 Tanning Salon 笔记
- poj 1250 Tanning Salon 和hotel一样
- poj 1250 Tanning Salon(模拟)
- POJ 1250 Tanning Salon(简单模拟)
- poj 1250 Tanning Salon 【模拟题】
- 1250 Tanning Salon
- poj 1250 Tanning Salon(基础题)模拟
- 记录如何修改桌面文件路径
- vim 官方网站代替
- “发明在商业上获得成功”对专利法22条第三款有关创造性规定的影响
- hdu 2795 Billboard
- Vector实现线程安全
- poj-1250Tanning Salon
- 一大坨GoogleAPI的学习笔记之二(oAuth2.0总结)
- iptables学习 01
- hdu - 4627 - The Unsolvable Problem
- Cocos2D-iphone CCLayer中的两种触摸(touch)处理方式
- Sftp和ftp 区别、工作原理等(汇总ing)
- hdu-统计元音
- CodeForces-MemSQL start[c]up Round 1-A. Square and Rectangles
- Starling在应用于移动设备开发时的注意事项