寒光博客

[Codeforces]#578 A. Hotelier 签到题
Codeforces Round #578 (Div. 2), problem: (A) Hotelier htt...
扫描右侧二维码阅读全文
11
2019/08

[Codeforces]#578 A. Hotelier 签到题

Codeforces Round #578 (Div. 2), problem: (A) Hotelier
https://codeforces.com/contest/1200/problem/A

题目

Hotelier

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 n 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 x (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 (0, 1, ..., 9) 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.

input

8
LLRL1RL1

output

1010000011

题目大意

0-9的房间,输入指令,包括LR和0-9的数字,l,r分别代表从最左最右 依次入住房间。数字代表退房。每次lr都是从最左最右开始入住
翻译指令即可

分析

嗯模拟 类似于队列,但是 问题不复杂遍历输入然后进行对应操作,每次都从最左最右开始即可。

代码

import java.util.Scanner;

public class Main {
    static int[] room = new int[10];
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int n = cin.nextInt();
        char[] res;
        res = cin.next().toCharArray();
        for (int i = 0; i < n; i++) {
            if (res[i] == 'L')
                leftInput();
            else if (res[i] == 'R')
                rightInput();
             else
                room[res[i] - '0'] = 0;
        }
        for (int i = 0; i < room.length; i++) {
            System.out.print(room[i]);
        }
    }
    private static void leftInput() {
        for (int i = 0; i < 10; i++)
            if (room[i] == 0) {
                room[i] = 1;break;
            }
    }
    private static void rightInput() {
        for (int i = 9; i >= 0; i--)
            if (room[i] == 0) {
                room[i] = 1;break;
            }
    }
}
本文作者:Author:     文章标题:[Codeforces]#578 A. Hotelier 签到题
本文地址:https://dxoca.cn/Algorithm/242.html       百度已收录
版权说明:若无注明,本文皆为“Dxoca's blog (寒光博客)”原创,转载请保留文章出处。
Last modification:August 12th, 2019 at 06:58 pm
如果觉得我的文章对你有用,请随意赞赏

Leave a Comment