题解 | #涂颜料#

涂颜料

https://www.nowcoder.com/practice/4ef038ae1c5f4524b8a8a0c1e6b062a1

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        int opr = scanner.nextInt();
        int[] numList = new int[num+2];
        for (int i = 0; i < opr; i++) {
            int start = scanner.nextInt();
            int endpt = scanner.nextInt();
            numList[start] ++;
            numList[endpt + 1] --;
        }
        String[] string = {"R", "G", "B"};
        for (int i = 1; i <= num; i++) numList[i] += numList[i-1];
        for (int i = 1; i <= num; i++) {
            int k = numList[i];
            if (k == 0) System.out.print("O");
            else {
                k = (k - 1) % 3;
                System.out.print(string[k]);
            }
        }
    }
}

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务