CF1200A

解法:

给出长度为n的字符串,字符串由'L'、'R'以及数字0~9组成。旅馆有10间房子,L代表客人从左边入住,R代表客人从右边入住,数字则表示第i间房子客人退房了。问经过这n次操作后,现在的旅店入住情况。

解法:

直接暴力模拟。

CODE:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<cstring>
#include<string>
#include<stack>
using namespace std; int room[1010],n;
string s; int main() {
scanf("%d",&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];
//system("pause");
return 0;
}

CF1200A的更多相关文章

随机推荐

  1. Html Agility Pack 使用 XPath 选择器

    想做一个爬虫程序,以前用的一直使用CSS选择器的html解析插件,最近做的项目想使用 Html Agility Pack 来做解析 Html Agility Pack使用 XPath 和 Linq 来 ...

  2. sql过程的条件是IN,用脚本执行

    DECLARE @sql nvarchar(); DECLARE @inStr nvarchar(); SET @inStr='''条件1'',''条件2'''; set @sql='SELECT * ...

  3. .NET Core 常用第三方包

    .NET Core 常用第三方包 作者:高堂 原文地址:https://www.cnblogs.com/gaotang/p/10845370.html 写在前面 最近在学习.NET Core 中经常用 ...

  4. 踩坑记录-nuxt引入vuex报错store/index.js should export a method that returns a Vuex instance.

    错误 store/index.js代码如下: import Vue from 'vue'; import Vuex from 'vuex'; import city from './moudle/ci ...

  5. springboot启动流程(二)SpringApplication run方法核心逻辑

    所有文章 https://www.cnblogs.com/lay2017/p/11478237.html run方法逻辑 在上一篇文章中,我们看到SpringApplication的静态方法最终是去构 ...

  6. UDP及操作系统理论

    UDP介绍 udp协议又称用户数据报协议 在OSI七层模型中,它于TCP共同存在于传输层 仅用于不要求可靠性,不要求分组顺序且数据较小的简单传输,力求速度 UDP结合socket用法 1.创建sock ...

  7. php获取客户机mac地址

    @exec("arp -a",$array); //执行arp -a命令,结果放到数组$array中 foreach($array as $value){ //匹配结果放到数组$m ...

  8. Cryptography -- 密码学

    Introduction to Cryptography Cryptography enables you to store sensitive information or transmit it ...

  9. 自适应高度文本框 react contenteditable

    import React, { Component } from 'react'; import PropTypes from 'prop-types'; const reduceTargetKeys ...

  10. Oracle学习笔记——Linux下开启Oracle

    1.开启数据库 sqlplus  /  as sysdba startup 2.启动监听:lsnrctl  start; 查看监听状态:lsnrctl status; 3.登入数据库 Linux 设置 ...