Algorithm, Problem Solving/백준(boj)

[백준][Java] 2799 - 블라인드

태오님 2023. 12. 9.

목차

     

    문제 정보

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

     

    2799번: 블라인드

    첫째 줄에 M과 N이 공백으로 구분해서 주어진다. (1 ≤ M, N ≤ 100) 다음 줄에는 현재 건너편 아파트의 상태가 주어진다. 모든 창문은 문제 설명에 나온 것 처럼 4*4 그리드로 주어진다. 또, 창문과

    www.acmicpc.net

    난이도 : S4

    유형 : String, Implementation

    시간 : O(N * M)


    코드

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.StringTokenizer;
    
    public class Main {
    
        final int TYPES = 5;
        int N;
        int M;
        char[][] board;
        int[] res;
    
        private int searchType(int x, int y) {
            int cnt = 0;
            for (int i = 0; i < 4; i++) {
                if (board[x + i][y] != '*') {
                    break;
                }
                cnt++;
            }
            return cnt;
        }
    
        private void solution() throws IOException {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            StringBuilder sb = new StringBuilder();
            StringTokenizer st = new StringTokenizer(br.readLine());
            N = Integer.parseInt(st.nextToken());
            M = Integer.parseInt(st.nextToken());
    
            board = new char[N * 5 + 1][M * 5 + 1];
            for (int i = 0; i < board.length; i++) {
                board[i] = br.readLine().toCharArray();
            }
    
            res = new int[TYPES];
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < M; j++) {
                    res[searchType(i * 5 + 1, j * 5 + 1)]++;
                }
            }
    
            for (int i = 0; i < res.length; i++) {
                sb.append(res[i]).append(" ");
            }
            System.out.println(sb);
        }
    
    
        public static void main(String[] args) throws IOException {
            new Main().solution();
        }
    }

    댓글