思考之后再看题解,是与别人灵魂之间的沟通与碰撞


A. Hotelier

题意 给出长度为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;
}

最新文章

  1. 使用TCMalloc的堆栈检查
  2. CGContextRef 绘图
  3. python 把数据 json格式输出
  4. 2016年6月24日 星期五 --出埃及记 Exodus 14:21
  5. B-树和B+树的应用:数据搜索和数据库索引
  6. latex插图续
  7. SQL其他常用的语句
  8. MVC动态赋值的td选中,获取当前的td的ID或者值
  9. 解决PowerDesigner不同表输入相同字段名被禁止问题
  10. face detection[Face R-FCN]
  11. 数据库截取字符串SUBSTR函数的使用
  12. linux 下的ssh免密登陆设置
  13. 如何三招帮你排查Linux中的硬件问题
  14. 如何接好CAN的“地”
  15. killall命令详解
  16. CAD常见问题
  17. 使用 NamedScope 扩展 Ninject 的 InRequestScope
  18. WebService的初级学习
  19. 加油吧 骚年QAQ
  20. 【BZOJ4145】[AMPPZ2014]The Prices 状压DP

热门文章

  1. Java自学-控制流程 continue
  2. 【开发笔记】- QQ消息轰炸
  3. 关于创建Web图像时应记住的五个要素
  4. openresty应用场景以及研发网关系统功能说明
  5. java requestmapping中关于路径的问题
  6. RocketMQ在CentOS7上安装
  7. php操作mysql,1分钟内插入百万数据
  8. docker安装mysql5.6(win10家庭版)
  9. 【Mybatis异常】Caused by: java.sql.SQLException: Parameter index out of range (1 &gt; number of parameters, which is 0).
  10. 什么影响了mysql的性能-硬件资源及系统方面优化