#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; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-12-29 19:32:04