ddubi

[백준] 2563번 : 색종이 - JAVA [자바] 본문

코테 문제풀이

[백준] 2563번 : 색종이 - JAVA [자바]

ddubi__ 2022. 12. 18. 21:58

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

 

2563번: 색종이

첫째 줄에 색종이의 수가 주어진다. 이어 둘째 줄부터 한 줄에 하나씩 색종이를 붙인 위치가 주어진다. 색종이를 붙인 위치는 두 개의 자연수로 주어지는데 첫 번째 자연수는 색종이의 왼쪽 변

www.acmicpc.net


paintColor ➜ x,y를 받아와서 해당 네모(10x10) 만큼 색칠해주기

checkColor ➜ 색칠된 영역 넓이 구하기

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main { // 색종이

    static boolean[][] area = new boolean[100][100];
    static final int size = 10;

    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            int N = Integer.valueOf(br.readLine());
            for(int i=0; i<N; i++){
                String temp[] = br.readLine().split(" ");
                int x = Integer.valueOf(temp[0]);
                int y = Integer.valueOf(temp[1]);
                paintArea(x,y);
            }
        } catch (NumberFormatException e){
            e.printStackTrace();
        } catch (Exception e){
            e.printStackTrace();
        }

        int num = checkColor(area);
        System.out.println(num);
    }

    private static int checkColor(boolean[][] area) {
        int cnt = 0;
        for(int i=0; i<area.length; i++){
            for (int j=0; j<area[i].length; j++){
                if(area[i][j]) cnt ++;
            }
        }
        return cnt;
    }

    private static void paintArea(int x, int y) {
        for(int i=x; i<x + size; i++){
            for(int j=y; j<y+size; j++){
                area[i][j] = true;
            }
        }
    }
}
Comments