【cf补题记录】A. Hotelier
2024-10-19 16:30:56
思考之后再看题解,是与别人灵魂之间的沟通与碰撞
题意 给出长度为n的字符串,字符串由'L'、'R'以及数字0~9组成。旅馆有10间房子,L代表客人从左边入住,R代表客人从右边入住,数字则表示第i间房子客人退房了。问经过这n次操作后,现在的旅店入住情况。
分析 n的范围比较小,完全可以暴力模拟实现。'L'就从左往右遍历看有没有空的房子,'R‘就从右往左遍历有没有空的房子。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<cstring>
#include<string>
#include<stack>
using namespace std;
int room[11];
string s;
int n;
int main()
{
memset(room, 0, sizeof(room));
cin >> n;
cin >> s;
for(int i = 0; i < s.size(); i++){
if(s[i] == 'L'){
for(int j = 0; j < 10; j++){
if(room[j] == 0){
room[j] = 1;
break;
}
}
}
else if(s[i] == 'R'){
for(int j = 9; j >= 0; j--){
if(room[j] == 0){
room[j] = 1;
break;
}
}
}
else if('0' <= s[i] && s[i] <= '9'){
int num = s[i] - '0';
room[num] = 0;
}
}
for(int i = 0; i < 10; i++){
cout << room[i];
} cout << endl;
return 0;
}
最新文章
- 使用TCMalloc的堆栈检查
- CGContextRef 绘图
- python 把数据 json格式输出
- 2016年6月24日 星期五 --出埃及记 Exodus 14:21
- B-树和B+树的应用:数据搜索和数据库索引
- latex插图续
- SQL其他常用的语句
- MVC动态赋值的td选中,获取当前的td的ID或者值
- 解决PowerDesigner不同表输入相同字段名被禁止问题
- face detection[Face R-FCN]
- 数据库截取字符串SUBSTR函数的使用
- linux 下的ssh免密登陆设置
- 如何三招帮你排查Linux中的硬件问题
- 如何接好CAN的“地”
- killall命令详解
- CAD常见问题
- 使用 NamedScope 扩展 Ninject 的 InRequestScope
- WebService的初级学习
- 加油吧 骚年QAQ
- 【BZOJ4145】[AMPPZ2014]The Prices 状压DP
热门文章
- Java自学-控制流程 continue
- 【开发笔记】- QQ消息轰炸
- 关于创建Web图像时应记住的五个要素
- openresty应用场景以及研发网关系统功能说明
- java requestmapping中关于路径的问题
- RocketMQ在CentOS7上安装
- php操作mysql,1分钟内插入百万数据
- docker安装mysql5.6(win10家庭版)
- 【Mybatis异常】Caused by: java.sql.SQLException: Parameter index out of range (1 >; number of parameters, which is 0).
- 什么影响了mysql的性能-硬件资源及系统方面优化