码迷,mamicode.com
首页 > 其他好文 > 详细

POJ-1250

时间:2015-07-25 18:27:28      阅读:116      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!