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;
}
//第一个在序列中出现的代表到来,第二个在序列出现的代表离开
//思路:枚举几个状态然后用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;
}
相关文章推荐
- 一个简单的AJAX实现,基于C#的ASP.Net,包括服务器端的程序代码
- 基于 XMPP协议的服务器端 文件互传的简单实现
- 基于SNMP的MIB库访问实现两个简单的画验证码图形程序
- 基于 XMPP协议的服务器端 文件互传的简单实现 (转)
- .net平台 基于 XMPP协议的即时消息服务端简单实现 (转)
- 基于Java实现简单Http服务器之一
- Castle AOP 系列(四):实现一个简单的基于上下文调用的权限校验机制
- 简单的颜色查看页面代码——基于DOM的实现
- 基于Ant+Velocity的简单代码生成器的思路与实现
- 基于 libmad 的简单 MP3 流媒体播放器的实现
- 基于 XMPP协议的服务器端 文件互传的简单实现
- 基于逻辑运算的简单权限系统(实现) JS 版
- 基于逻辑运算的简单权限系统(实现) JS 版
- 基于Ant+Velocity的简单代码生成器的思路与实现
- 基于逻辑运算的简单权限系统(实现) JS 版
- 基于Java实现简单Http服务器之一
- 基于逻辑运算的简单权限系统(原理,设计,实现) VBS 版
- 基于逻辑运算的简单权限系统(原理,设计,实现) VBS 版
- 基于Ant+Velocity的简单代码生成器的思路与实现
- 基于JAINSIP协议栈的一个简单SIP服务器实现流程