Hotelier

A. Hotelier

time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output
Amugae has a hotel consisting of 10 rooms. The rooms are numbered from 0 to 9 from left to right.

The hotel has two entrances — one from the left end, and another from the right end. When a customer arrives to the hotel through the left entrance, they are assigned to an empty room closest to the left entrance. Similarly, when a customer arrives at the hotel through the right entrance, they are assigned to an empty room closest to the right entrance.

One day, Amugae lost the room assignment list. Thankfully Amugae’s memory is perfect, and he remembers all of the customers: when a customer arrived, from which entrance, and when they left the hotel. Initially the hotel was empty. Write a program that recovers the room assignment list from Amugae’s memory.

Input

The first line consists of an integer n (1≤n≤105), the number of events in Amugae’s memory.

The second line consists of a string of length nn describing the events in chronological order. Each character represents:

‘L’: A customer arrives from the left entrance.
‘R’: A customer arrives from the right entrance.
‘0’, ‘1’, …, ‘9’: The customer in room xx (0, 1, …, 9 respectively) leaves.
It is guaranteed that there is at least one empty room when a customer arrives, and there is a customer in the room x when x (00, 11, …, 99) is given. Also, all the rooms are initially empty.

Output

In the only line, output the hotel room’s assignment status, from room 0 to room 9. Represent an empty room as ‘0’, and an occupied room as ‘1’, without spaces.

example

input
8
LLRL1RL1
output
1010000011
input
9
L0L0LLRR9
output
1100000010

AC代码

#include<cstdio>
#include <iostream>
#include<cstdlib>
#include <cstring>
const int maxn = 1e5+1;
int main()
{
    int a[10]={0};
    char c[maxn];
    int n,l,r,ch;
    scanf("%d",&n);
    for(int i=0;i<=n;i++)//看下面那张图,第一个他会把scanf自带的\n录进去,所以是<=n
        {
        scanf("%c",&c[i]);
        //std::cout<<c[i]<<std::endl;
        if(c[i]=='L') {
            //std::cout<<1;
            for (l = 0; l < 10; l++)
                if (a[l] == 0) {
                    a[l] = 1;
                    break;
                }
        }
        if(c[i]=='R') {
            //std::cout<<2;
            for (r = 9; r > -1; r--)
                if (a[r] == 0) {
                    a[r] = 1;
                    break;
                }
        }
        if(c[i]>='0'&&c[i]<='9')
        {
            //std::cout<<3;
            ch=(int)c[i]-'0';
            a[ch]=0;
        }
       // std::cout<<"---- "<<i<<std::endl;
        //for(int i=0;i<10;i++)
            //printf("%d",a[i]);
        //std::cout<<std::endl;

    }
    for(int i=0;i<10;i++)
        printf("%d",a[i]);
    return 0;
}

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值