poj 1250 Tanning Salon
2011-11-21 10:28
239 查看
Tanning Salon
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
Sample Output
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 5384 | Accepted: 2943 |
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.
#include<iostream> using namespace std; int main() { int n; char guest[200]; char bed[21]; int bed_left; int len; int i,j,k; int leave; while(1) { cin>>n; if(n==0) break; cin>>guest; bed_left=n; leave=0; len=strlen(guest); for(i=0;i<n;i++) bed[i]=''; for(i=0;i<len;i++) { if(guest[i]=='') continue; for(j=0;j<n;j++) { if(guest[i]==bed[j]) { bed[j]=''; bed_left++; break; } } if(j==n) { if(bed_left!=0) { for(k=0;k<n;k++) { if(bed[k]=='') { bed[k]=guest[i]; bed_left--; break; } } } else { leave++; for(k=i+1;k<len;k++) { if(guest[k]==guest[i]) { guest[k]=''; } } } } } if(leave==0) cout<<"All customers tanned successfully."<<endl; else cout<<leave<<" customer(s) walked away."<<endl; } return 0; }
相关文章推荐
- poj 1250 Tanning Salon
- POJ 1250 tanning salon
- poj 1250 Tanning Salon 和hotel一样
- POJ 1250 Tanning Salon
- 【队列】poj1250 Tanning Salon
- POJ 1250 Tanning Salon(我的水题之路——字母表数组标记)
- POJ 1250 Tanning Salon
- POJ 1250 Tanning Salon
- POJ1250 Tanning Salon 简单模拟
- poj 1250 Tanning Salon(模拟)
- poj 1250 Tanning Salon
- POJ 1250 Tanning Salon
- poj1250 Tanning Salon
- poj1250 Tanning 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