首页 > 其他 > 详细

POJ-1250

时间:2015-07-25 18:26:33      阅读:294      评论:0      收藏:0      [点我收藏+]
#include<iostream>
#include<string>
#include<list>
#include<algorithm>
using namespace std;

int main(int argc, char *argv[]){
	int bedNum;
	string customer;
	while(cin>>bedNum,bedNum){
		int departCustomer=0;
		list<char> mList;
		cin>>customer;
		char *cp=new char[customer.length()+1];
		customer.copy(cp,customer.length(),0);
		*(cp+customer.length())='\0';

		for(int i=0;i<customer.length();i++){
			if(find(mList.begin(),mList.end(),cp[i])==mList.end()){
				if(bedNum==0){
					departCustomer++;
					i++;
					//cout<<cp[i]<<" depart"<<endl;
					continue;
				}

				mList.push_back(cp[i]);
				//cout<<"push: "<<cp[i]<<endl;
				bedNum--;
			}else{
				mList.remove(cp[i]);
				//cout<<"pop: "<<cp[i]<<endl;
				bedNum++;
			}

			//cout<<"bed num: "<<bedNum<<endl;
		}

		if(departCustomer==0){
			cout<<"All customers tanned successfully."<<endl;
		}else{
			cout<<departCustomer<<" customer(s) walked away."<<endl;
		}

		free(cp);
	}

	return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

POJ-1250

原文:http://blog.csdn.net/eddy_liu/article/details/47058361

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!