Open hitolz opened 5 years ago
https://codeforces.com/contest/1200/problem/A 题目内容: 说一个宾馆10个房间,从左到右标记为0-9,宾馆有两个入口,可以从左边进(L),也可以从右边进(R),数字表示对应的房间的人离开,输出这10个房间的状态,0表示没人,1表示有人。
import java.util.Scanner; public class Cf578A { static int n; public static void main(String[] args) { Scanner scanner = new Scanner(System.in); n = scanner.nextInt(); scanner.nextLine(); String input = scanner.nextLine(); int[] room = new int[10]; for (int i = 0; i < n; i++) { char c = input.charAt(i); if ('L' == c) { inFromLeft(room); } else if ('R' == c) { inFromRight(room); } else { leave(room, c); } } print(room); } private static void print(int[] room) { for (int i = 0; i <= 9; i++) { System.out.print(room[i]); } } private static void leave(int[] room, char c) { int num = Integer.parseInt(String.valueOf(c)); room[num] = 0; } private static void inFromRight(int[] room) { for (int i = 9; i >= 0; i--) { if (room[i] == 0) { room[i] = 1; break; } } } private static void inFromLeft(int[] room) { for (int i = 0; i <= 9; i++) { if (room[i] == 0) { room[i] = 1; break; } } } }
https://codeforces.com/contest/1200/problem/A 题目内容: 说一个宾馆10个房间,从左到右标记为0-9,宾馆有两个入口,可以从左边进(L),也可以从右边进(R),数字表示对应的房间的人离开,输出这10个房间的状态,0表示没人,1表示有人。