您的位置:首页 > 编程语言 > Go语言

poj1250基于enum较简单的实现

2014-09-14 21:37 267 查看
//题意:输入一个数字表示有的空的沙龙床位,然后一个序列

//第一个在序列中出现的代表到来,第二个在序列出现的代表离开

//思路:枚举几个状态然后用map对应每个字母的状态
//244K 0MS

#include <iostream>
#include <algorithm>
#include <string>
#include <map>
using namespace std;

enum {
NOT_LEAVE,
LEAVE,
USED
};
int main(){
int N;
while(cin>>N&&N){
string str;
int nempty = N;
int nwalk = 0;
cin>>str;
map<int,int>mleave;
for (int i=0;i<str.size();++i)
mleave[str[i]-'A'] = NOT_LEAVE;
nempty-=1;
mleave[str[0]-'A'] = USED;
for (int i=1;i<str.size();++i)
{
if (mleave[str[i]-'A']==USED)
{
mleave[str[i]-'A'] = LEAVE;
nempty+=1;
continue;
}
else if (nempty!=0 &&mleave[str[i]-'A']==NOT_LEAVE)
{
mleave[str[i]-'A'] = USED;
nempty-=1;
continue;
}
else{
if (mleave[str[i]-'A']==LEAVE)
continue;
mleave[str[i]-'A']= LEAVE;
nwalk+=1;
}
}
if (nwalk==0)
printf("All customers tanned successfully.\n");
else
printf("%d customer(s) walked away.\n",nwalk);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  struct poj enum map algorithm