[백준] 2578 빙고

문제링크 : https://www.acmicpc.net/problem/2578

 

2578번: 빙고

첫째 줄부터 다섯째 줄까지 빙고판에 쓰여진 수가 가장 위 가로줄부터 차례대로 한 줄에 다섯 개씩 빈 칸을 사이에 두고 주어진다. 여섯째 줄부터 열째 줄까지 사회자가 부르는 수가 차례대로

www.acmicpc.net

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    static int[][] bingo;
    static int cnt;
    static int turn = 1;
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        bingo = new int[5][5];

        // 빙고 입력
        for (int i=0; i<5; i++){
            StringTokenizer st = new StringTokenizer(br.readLine());
            for (int j=0; j<5; j++){
                bingo[i][j] = Integer.parseInt(st.nextToken());
            }
        }

        for (int i=0; i<5; i++){
            StringTokenizer st = new StringTokenizer(br.readLine());
            for (int j=0; j<5; j++){
                int num = Integer.parseInt(st.nextToken());
                for (int x=0; x<5; x++){
                    for (int y=0; y<5; y++){
                        // 입력받은 수를 찾아서 0으로 변경
                        if (bingo[x][y] == num){
                            bingo[x][y] = 0;
                        }
                    }
                }
                chk_col();
                chk_row();
                chk_right();
                chk_left();

                if (cnt>=3){
                    System.out.println(turn);
                    System.exit(0);
                }

                cnt = 0;
                turn ++;
            }
        }
    }
    // 가로, 세로 확인
    public static void chk_col(){
        for (int i=0; i<5; i++){
            int count = 0;
            for (int j=0; j<5; j++){
                if (bingo[i][j] == 0){
                    count ++;
                }
                if (count == 5){
                    cnt ++;
                }
            }
        }
    }
    public static void chk_row(){
        for (int i=0; i<5; i++){
            int count = 0;
            for (int j=0; j<5; j++){
                if (bingo[j][i] == 0){
                    count ++;
                }
                if (count == 5){
                    cnt ++;
                }
            }
        }
    }
    // 대각선 확인
    public static void chk_right(){
        int count = 0;
        for (int i=0; i<5; i++){
            if (bingo[i][4-i] == 0){
                count ++;
            }
            if (count == 5){
                cnt ++;
            }
        }
    }
    public static void chk_left(){
        int count = 0;
        for (int i=0; i<5; i++){
            if (bingo[i][i] == 0){
                count ++;
            }
            if (count == 5){
                cnt ++;
            }
        }
    }
}

'Algorithm > Java' 카테고리의 다른 글

[백준] 2258 정육점  (0) 2024.02.17
[백준] 3020 개똥벌레  (1) 2024.02.10
[백준] 2583 영역구하기  (1) 2024.02.01
[백준] 17266 어두운 굴다리  (1) 2024.01.26
[백준] 4963 섬의 개수  (0) 2024.01.23