[백준] 2563. 색종이(실버5)

ERror.ASER·2021년 2월 9일
0

백준

목록 보기
11/69
post-thumbnail

백준(실버5) - 2563. 색종이(실버5)



풀이

처음 봤을때 겁먹었는데, 막상 풀어보니 10분컷이었당ㅎ
1. 가로, 세로의 크기가 각각 100인 흰색 도화지를 2차원 배열로 선언해주었다.
2. 그리고 입력받은 x,y를 기준으로 각각 가로와 세로가 10인 정사각형 안에 들어가는 범위들을 모두 1로 바꾸어주었다.
3. map이 1이면 count++을 해주었는데, 그냥 count += map[i][j]; 해줘도 된다.

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

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());//색종이의 수
		int[][] map = new int[100][100];//도화지
		int count = 0;
		for(int t = 0; t<n; t++) {
			StringTokenizer st = new StringTokenizer(br.readLine());
			int x = Integer.parseInt(st.nextToken());
			int y = Integer.parseInt(st.nextToken());
			
			for(int i=x; i<x+10; i++) {
				for(int j=y; j<y+10; j++) {
					map[i][j] = 1;
				}
			}
		}
		for(int i=0; i<100; i++) {
			for(int j=0; j<100; j++) {
				if(map[i][j] == 1) count++;
			}
		}
		System.out.println(count);
	}
}
profile
지우의 블로그

0개의 댓글