[백준] 2447번 : 별 찍기 - 10 - JAVA [자바]
www.acmicpc.net/problem/2447 2447번: 별 찍기 - 10 재귀적인 패턴으로 별을 찍어 보자. N이 3의 거듭제곱(3, 9, 27, ...)이라고 할 때, 크기 N의 패턴은 N×N 정사각형 모양이다. 크기 3의 패턴은 가운데에 공백..
st-lab.tistory.com
https://www.acmicpc.net/board/view/26520
글 읽기 - ★☆★☆★ [필독] 별찍기 - 11 FAQ ★☆★☆★
댓글을 작성하려면 로그인해야 합니다.
www.acmicpc.net
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static StringBuilder sb = new StringBuilder();
static int N;
static char[][] arr;
public static void main(String arg[]) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(br.readLine());
arr = new char[N][N*2-1];
for(int i = 0; i < N; i++) {
for(int j = 0; j < N*2-1; j++) {
arr[i][j] = ' ';
}
}
func(N, N-1, 0);
for(int i = 0; i < N; i++) {
for(int j = 0; j < N*2-1; j++) {
sb.append(arr[i][j]);
}
sb.append('\n');
}
System.out.println(sb.toString());
}
static void star(int rx, int ry) {
arr[rx][ry] = '*';
arr[rx+1][ry-1] = '*';
arr[rx+1][ry+1] = '*';
for(int i = 0; i < 5; i++) {
arr[rx+2][ry-2+i] = '*';
}
}
static void func(int depth, int first_space, int start_x) {
if(depth == 3) {
star(start_x, first_space);
return;
}
int size = depth/2;
func(size, first_space, start_x); // 6 12 0
func(size, first_space-size, start_x+size);
func(size, first_space+size, start_x+size);
}
}
'백준' 카테고리의 다른 글
[백준] 12865 평범한 배낭 [자바] (0) | 2022.05.06 |
---|---|
[백준] 11725 트리의 부모 찾기 [자바] (0) | 2022.05.04 |
[백준] 1629 곱셈 [자바] (0) | 2022.04.22 |
[백준] 1043 거짓말 [자바] (0) | 2022.04.21 |
[백준] 16236 아기 상어 [자바] (0) | 2022.04.19 |