POJ-1250

时间:2023-03-09 05:32:45
POJ-1250
#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;
}