POJ1250:Tanning Salon
2014-03-01 21:55
302 查看
DescriptionTanYourHide,Inc.,ownsseveralcoin-operatedtanningsalons.Researchhasshownthatifacustomerarrivesandtherearenobedsavailable,thecustomerwillturnaroundandleave,thuscostingthecompanyasale.Yourtaskistowriteaprogramthattellsthecompanyhowmanycustomersleftwithouttanning.InputTheinputconsistsofdataforoneormoresalons,followedbyalinecontainingthenumber0thatsignalstheendoftheinput.Dataforeachsalonisasinglelinecontainingapositiveinteger,representingthenumberoftanningbedsinthesalon,followedbyaspace,followedbyasequenceofuppercaseletters.Lettersinthesequenceoccurinpairs.Thefirstoccurrenceindicatesthearrivalofacustomer,thesecondindicatesthedepartureofthatsamecustomer.Noletterwilloccurinmorethanonepair.Customerswholeavewithouttanningalwaysdepartbeforecustomerswhoarecurrentlytanning.Thereareatmost20bedspersalon.OutputForeachsalon,outputasentencetellinghowmanycustomers,ifany,walkedaway.Usetheexactformatshownbelow.SampleInput
2ABBAJJKZKZ 3GACCBDDBAGEE 3GACCBGDDBAEE 1ABCBCA 0SampleOutput
Allcustomerstannedsuccessfully. 1customer(s)walkedaway. Allcustomerstannedsuccessfully. 2customer(s)walkedaway.
题意:有n个位置,每个字母第一次出现代表客人的进来,第二次出现代表离开 统计流失了几个客户
#include<stdio.h>#include<string.h>#include<algorithm>usingnamespacestd;chars[100005];intmain(){intn;while(~scanf("%d",&n),n){intl=0,i,j,flag,len;scanf("%s",s);len=strlen(s);charz[25];//Z数组存床是否有人memset(z,'#',sizeof(z));for(i=0;i<len;i++){flag=0;//flag=0表示进入for(j=1;j<=n;j++)//离开后位置清空if(z[j]==s[i]){z[j]='#';flag=1;break;}if(flag==0)for(j=1;j<=n;j++)//有空位置就让顾客进去if(z[j]=='#'){z[j]=s[i];break;}if(j>n)//没有空位置流失人数加一l++;}if(l==0)printf("Allcustomerstannedsuccessfully.\n");elseprintf("%dcustomer(s)walkedaway.\n",l/2);}return0;}
相关文章推荐
- 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 1250 Tanning Salon 和hotel一样
- 【队列】poj1250 Tanning Salon
- POJ 1250 Tanning Salon
- POJ 1250 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 【模拟题】