Skip to content

Instantly share code, notes, and snippets.

@dalcon10028
Created January 1, 2020 07:42
Show Gist options
  • Save dalcon10028/4b69cf3c2a085724d53553f2d6f805e8 to your computer and use it in GitHub Desktop.
Save dalcon10028/4b69cf3c2a085724d53553f2d6f805e8 to your computer and use it in GitHub Desktop.
import java.util.*;
public class Main {
static char field[][];
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
sc.close();
field = new char[N][N];
StringBuilder sb = new StringBuilder();
for(int i=0;i<N;i++) Arrays.fill(field[i],' ');
star(N, 0, 0);
for(int i= 0; i<N; i++){
for(int j=0; j<N; j++)
sb.append(field[i][j]);
sb.append("\n");
}
System.out.println(sb);
}
public static void star(int n, int x, int y) {
if (n==1) { // 마지막 처리
field[y][x] = '*';
return;
}
star(n/3, x, y); // 좌상
star(n/3, x+n/3, y); // 상
star(n/3, x+n/3*2, y); // 우상
star(n/3, x, y+n/3); // 좌
star(n/3, x+n/3*2, y+n/3); // 우
star(n/3, x, y+n/3*2); // 좌하
star(n/3, x+n/3, y+n/3*2); // 하
star(n/3, x+n/3*2, y+n/3*2); // 우하
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment