您的位置:首页 > 其它

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
0
SampleOutput
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;}

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: