2 minute read

๐Ÿ“Œ ๋‚œ์ด๋„

๐Ÿฅ‡ Gold 5


๐Ÿ“Œ ๋ฌธ์ œ

https://www.acmicpc.net/problem/14891

image

image

image

image


๐Ÿ“Œ ํ’€์ด


๐Ÿ“Œ Code

package BOJ.Implements;

import java.io.*;
import java.util.*;

public class N14891 {
    public static boolean[][] gear;

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        String str;
        gear = new boolean[4][8];
        for (int i = 0; i < 4; i++) {
            str = br.readLine();
            for (int j = 0; j < 8; j++) {
                if (str.charAt(j) == '0') {
                    gear[i][j] = false;
                } else {
                    gear[i][j] = true;
                }
            }
        }
        int K = Integer.parseInt(br.readLine());
        //ShowAll();
        for (int i = 0; i < K; i++) {
            st = new StringTokenizer(br.readLine());
            Rotate(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()));
        }
        Print12();
    }

    static void Rotate(int num, int dir) {
        if (num == 1) {
            if (CompareGear(0, 1)) {
                if (CompareGear(1, 2)) {
                    if (CompareGear(2, 3)) {
                        GearCounter(3, -dir);
                    }
                    GearCounter(2, dir);
                }
                GearCounter(1, -dir);
            }
            GearCounter(0, dir);
        } else if (num == 2) {
            if (CompareGear(0, 1)) {
                GearCounter(0, -dir);
            }
            if (CompareGear(1, 2)) {
                if (CompareGear(2, 3)) {
                    GearCounter(3, dir);
                }
                GearCounter(2, -dir);
            }
            GearCounter(1, dir);
        } else if (num == 3) {
            if (CompareGear(1, 2)) {
                if (CompareGear(0, 1)) {
                    GearCounter(0, dir);
                }
                GearCounter(1, -dir);
            }
            if (CompareGear(2, 3)) {
                GearCounter(3, -dir);
            }
            GearCounter(2, dir);
        } else {
            if (CompareGear(2, 3)) {
                if (CompareGear(1, 2)) {
                    if (CompareGear(0, 1)) {
                        GearCounter(0, -dir);
                    }
                    GearCounter(1, dir);
                }
                GearCounter(2, -dir);
            }
            GearCounter(3, dir);
        }
        //ShowAll();
    }

    static void Print12() {
        int result = 0;
        if (gear[0][0]) {
            result += 1;
        }
        if (gear[1][0]) {
            result += 2;
        }
        if (gear[2][0]) {
            result += 4;
        }
        if (gear[3][0]) {
            result += 8;
        }
        System.out.println(result);
    }

    static void ShowAll() {
        System.out.println("    v       v");
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 8; j++) {
                if (!gear[i][j]) {
                    System.out.print("0 ");
                } else {
                    System.out.print("1 ");
                }
            }
            System.out.println();
        }
        System.out.println("===========================");
    }

    static boolean CompareGear(int a, int b) {
        if (gear[a][2] != gear[b][6]) {
            return true;
        } else {
            return false;
        }
    }

    static void GearCounter(int num, int dir) {
        if (dir == 1) {
            boolean save = gear[num][7];
            for (int i = 7; i > 0; i--) {
                gear[num][i] = gear[num][i - 1];
            }
            gear[num][0] = save;
        } else {
            boolean save = gear[num][0];
            for (int i = 0; i < 7; i++) {
                gear[num][i] = gear[num][i + 1];
            }
            gear[num][7] = save;
        }
    }
}

package (์ด๋ฆ„); ๋ฅผ ๋•Œ๊ณ , class ์ด๋ฆ„์„ Main์œผ๋กœ ๋ณ€๊ฒฝํ•˜๋ฉด ๋œ๋‹ค.


๐Ÿ“Œ ์ถ”๊ฐ€ ์˜ˆ์ œ

[Input]
10101111
01111101
11001110
00000010
2
1 -1
1 1

[Output]
5
[Input]
11111110
00000000
11111111
11111111
1
2 -1

[Output]
12


๊ฐœ์ธ ๊ณต๋ถ€ ๊ธฐ๋ก์šฉ ๋ธ”๋กœ๊ทธ์ž…๋‹ˆ๋‹ค.
ํ‹€๋ฆฌ๊ฑฐ๋‚˜ ์˜ค๋ฅ˜๊ฐ€ ์žˆ์„ ๊ฒฝ์šฐ ์ œ๋ณดํ•ด์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.๐Ÿ˜