https://www.acmicpc.net/problem/2447
재귀적인 패턴으로 별을 찍어 보자. N이 3의 거듭제곱(3, 9, 27, ...)이라고 할 때, 크기 N의 패턴은 N×N 정사각형 모양이다.
크기 3의 패턴은 가운데에 공백이 있고, 가운데를 제외한 모든 칸에 별이 하나씩 있는 패턴이다.
***
* *
***
N이 3보다 클 경우, 크기 N의 패턴은 공백으로 채워진 가운데의 (N/3)×(N/3) 정사각형을 크기 N/3의 패턴으로 둘러싼 형태이다. 예를 들어 크기 27의 패턴은 예제 출력 1과 같다.
첫째 줄에 N이 주어진다. N은 3의 거듭제곱이다. 즉 어떤 정수 k에 대해 N=3k이며, 이때 1 ≤ k < 8이다.
import java.io.*;
import java.util.Arrays;
public class starMake_2447 {
static char[][] arr;
public static void solution() throws IOException{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n = Integer.parseInt(bf.readLine());
arr = new char[n][n];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
arr[i][j] = ' ';
}
}
star(0,0,n);
for(int i=0;i<n;i++){
bw.write(arr[i]);
bw.write("\n");
}
bw.flush();
bw.close();
}
public static void star(int x, int y,int n){
if(n==1){
arr[x][y] = '*';
return;
}
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
if(!(i==1 && j==1)){
star(x+i*(n/3), y+j*(n/3),n/3);
}
}
}
}
}