zoukankan      html  css  js  c++  java
  • CF1200A

    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;
    }
    
  • 相关阅读:
    605. Can Place Flowers
    1184. Distance Between Bus Stops
    1711. Count Good Meals
    1710. Maximum Units on a Truck
    566. Reshape the Matrix
    980. Unique Paths III
    212. Word Search II
    每日总结
    每日总结
    每日总结
  • 原文地址:https://www.cnblogs.com/Repulser/p/11431961.html
Copyright © 2011-2022 走看看