Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- class Main {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String[] wheel = new String[5];
- wheel[1] = sc.nextLine();
- wheel[2] = sc.nextLine();
- wheel[3] = sc.nextLine();
- wheel[4] = sc.nextLine();
- int k = sc.nextInt();
- for (int a = 0; a < k; a++) {
- int[] d = new int[5];
- int n = sc.nextInt();
- d[n] = sc.nextInt();
- for (int b = n - 1; b >= 1; b--) {
- if (wheel[b].charAt(2) != wheel[b + 1].charAt(6)) {
- d[b] = -d[b + 1];
- }
- }
- for (int b = n + 1; b <= 4; b++) {
- if (wheel[b].charAt(6) != wheel[b - 1].charAt(2)) {
- d[b] = -d[b - 1];
- }
- }
- for (int b = 1; b <= 4; b++) {
- rotate(wheel, b, wheel[b], d[b]);
- }
- }
- int answer = 0;
- if (wheel[1].charAt(0) == '1') {
- answer += 1;
- }
- if (wheel[2].charAt(0) == '1') {
- answer += 2;
- }
- if (wheel[3].charAt(0) == '1') {
- answer += 4;
- }
- if (wheel[4].charAt(0) == '1') {
- answer += 8;
- }
- System.out.println(answer);
- sc.close();
- }
- private static void rotate(String[] wheel, int b, String string, int i) {
- if (i == 1) {
- char c = string.charAt(7);
- String s = string.substring(0, 7);
- wheel[b] = c + s;
- } else if (i == -1) {
- char c = string.charAt(0);
- String s = string.substring(1, 8);
- wheel[b] = s + c;
- }
- }
- }
Add Comment
Please, Sign In to add comment