## 과제 : 백준 문제 풀이 목표 : 백준 문제를 풀어본다. - [종이의 개수](https://www.acmicpc.net/problem/1780) - [Z](https://www.acmicpc.net/problem/1074) - [별 찍기 - 10](https://www.acmicpc.net/problem/2447) ## 과제 : 백준 문제 풀이 모범답안 ### 종이의 개수 ```java import java.io.*; import java.util.Scanner; public class Main { static int[][] paper; static int minusOne = 0, zero = 0, one = 0; public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); int N = Integer.parseInt(sc.nextLine()); paper = new int[N][N]; for (int i = 0; i < N; i++) { String[] row = sc.nextLine().split(" "); for (int j = 0; j < N; j++) { paper[i][j] = Integer.parseInt(row[j]); } } solve(0, 0, N); System.out.println(minusOne); System.out.println(zero); System.out.println(one); } public static void solve(int x, int y, int N) { if (check(x, y, N)) { if (paper[x][y] == -1) { minusOne++; } else if (paper[x][y] == 0) { zero++; } else { one++; } return; } int size = N / 3; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { solve(x + i * size, y + j * size, size); } } } public static boolean check(int x, int y, int N) { int value = paper[x][y]; for (int i = x; i < x + N; i++) { for (int j = y; j < y + N; j++) { if (value != paper[i][j]) { return false; } } } return true; } } ``` ### Z ```java import java.io.*; import java.util.Scanner; public class Main { static int N, r, c; static int count = 0; public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); String[] input = sc.nextLine().split(" "); N = Integer.parseInt(input[0]); r = Integer.parseInt(input[1]); c = Integer.parseInt(input[2]); solve((int)Math.pow(2, N), 0, 0); } public static void solve(int size, int x, int y) { if (x == r && y == c) { System.out.println(count); return; } if (r < x + size && r >= x && c < y + size && c >= y) { int newSize = size / 2; solve(newSize, x, y); solve(newSize, x, y + newSize); solve(newSize, x + newSize, y); solve(newSize, x + newSize, y + newSize); } else { count += size * size; } } } ``` ### 별 찍기 - 10 ```java import java.io.*; import java.util.Scanner; public class Main { static char[][] arr; public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); int N = Integer.parseInt(sc.nextLine()); arr = new char[N][N]; solve(0, 0, N, false); StringBuilder sb = new StringBuilder(); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { sb.append(arr[i][j]); } sb.append('\n'); } System.out.println(sb); } public static void solve(int x, int y, int N, boolean blank) { if (blank) { for (int i = x; i < x + N; i++) { for (int j = y; j < y + N; j++) { arr[i][j] = ' '; } } return; } if (N == 1) { arr[x][y] = '*'; return; } int size = N / 3; int count = 0; for (int i = x; i < x + N; i += size) { for (int j = y; j < y + N; j += size) { count++; if (count == 5) { solve(i, j, size, true); } else { solve(i, j, size, false); } } } } } ```