Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

21.08.17 - [BOJ] 15662. 톱니바퀴 (2) #163

Closed
suhyunsim opened this issue Aug 17, 2021 · 0 comments
Closed

21.08.17 - [BOJ] 15662. 톱니바퀴 (2) #163

suhyunsim opened this issue Aug 17, 2021 · 0 comments
Assignees
Labels
성공 맞은 문제 시뮬레이션 실버 BOJ - 실버

Comments

@suhyunsim
Copy link
Owner

suhyunsim commented Aug 17, 2021

문제

핵심 아이디어

  • 톱니바퀴 문제와 비슷한데 4를 N으로 바꾸기

어려운 점, 실수

풀이

package main.java.com.poogle.BOJ.Q15662;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[][] a = new char[n][8];
        for (int i = 0; i < n; i++) {
            a[i] = sc.next().toCharArray();
        }
        int k = sc.nextInt();
        while (k-- > 0) {
            int no = sc.nextInt() - 1;
            int dir = sc.nextInt();
            //각 톱니가 어떤 방향으로 회전하는지
            int[] d = new int[n];
            d[no] = dir;
            //왼쪽
            for (int i = no - 1; i >= 0; i--) {
                if (a[i][2] != a[i + 1][6]) {
                    d[i] = -d[i + 1];
                } else {
                    break;
                }
            }
            //오른쪽
            for (int i = no + 1; i < n; i++) {
                if (a[i - 1][2] != a[i][6]) {
                    d[i] = -d[i - 1];
                } else {
                    break;
                }
            }
            for (int i = 0; i < n; i++) {
                if (d[i] == 0) continue;
                if (d[i] == 1) {
                    //시계방향
                    char temp = a[i][7];
                    for (int j = 7; j >= 1; j--) {
                        a[i][j] = a[i][j - 1];
                    }
                    a[i][0] = temp;
                } else if (d[i] == -1) {
                    //반시계방향
                    char temp = a[i][0];
                    for (int j = 0; j < 7; j++) {
                        a[i][j] = a[i][j + 1];
                    }
                    a[i][7] = temp;
                }
            }
        }
        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (a[i][0] == '1') {
                ans += 1;
            }
        }
        System.out.println(ans);
    }
}
@suhyunsim suhyunsim self-assigned this Aug 17, 2021
@suhyunsim suhyunsim added this to the 8월 4주 차 milestone Aug 29, 2021
@suhyunsim suhyunsim changed the title 21.08.17 - [BOJ] 15662. 톱니바퀴2 21.08.17 - [BOJ] 15662. 톱니바퀴 (2) Aug 29, 2021
@suhyunsim suhyunsim added 실버 BOJ - 실버 실패 시도했지만 맞지 못한 문제 성공 맞은 문제 시뮬레이션 and removed 실패 시도했지만 맞지 못한 문제 labels Aug 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
성공 맞은 문제 시뮬레이션 실버 BOJ - 실버
Projects
None yet
Development

No branches or pull requests

1 participant