当前位置: 首页 > 工具软件 > Hotelier > 使用案例 >

Codeforces--1200A--Hotelier

祝宾白
2023-12-01

题目描述:
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.
输入描述:
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.
输出描述:
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.
输入:
8
LLRL1RL1
9
L0L0LLRR9
输出:
1010000011
1100000010
题意:
Amugae的酒店由10人组成10客房。房间从0开始编号0到9 从左到右。 酒店有两个入口 - 一个来自左端,另一个来自右端。当顾客通过左入口到达酒店时,他们被分配到最靠近左入口的空房间。类似地,当顾客通过右入口到达酒店时,他们被分配到最靠近右入口的空房间。 有一天,Amugae失去了房间分配清单。值得庆幸的是,Amugae的记忆非常完美,他记得所有顾客:当顾客到达时,从哪个入口到他们离开酒店。最初酒店是空的。编写一个程序,从Amugae的记忆中恢复房间分配列表。
题解
直接暴力
代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;

const int maxn = 100000 + 5;
char s[maxn],op[15];

int main(){
    int n;
    while(scanf("%d%s",&n,s)!=EOF){
        for(int i = 0; i <= 9; i ++) op[i] = '0';
        int l = strlen(s);
        for(int i = 0; i < l; i ++){
            if(s[i] == 'L'){
                for(int i = 0; i <= 9; i ++){
                    if(op[i] == '0'){
                        op[i] = '1';
                        break;
                    }
                }
            }
            else if(s[i] == 'R'){
                for(int i = 9; i >= 0; i --){
                    if(op[i] == '0'){
                        op[i] = '1';
                        break;
                    }
                }
            }
            else{
                int t = s[i] - '0';
                op[t] = '0';
            }
        }
        for(int i = 0; i <= 9; i ++) printf("%c",op[i]);
        printf("\n");
    }
    return 0;
}
 类似资料:

相关阅读

相关文章

相关问答