首页 > 代码库 > POJ-1250
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; }
POJ-1250
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。