티스토리 뷰
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
import java.io.*;
import java.util.Scanner;
public class boj_2447 {
static char[][] map;
static int length;
static Scanner sc = new Scanner(System.in);
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
public static void main(String[] args) throws IOException {
length = sc.nextInt();
map = new char[length][length];
func(0, 0, length);
for (int i = 0; i < length; i++) {
for (int j = 0; j < length; j++) {
bw.write(map[i][j]);
}
bw.newLine();
}
bw.flush();
bw.close();
}
static void func(int x, int y, int length) {
// base condition
if (length == 1) return;
// mark
if (length == 3) {
for (int i = x; i < x + length; i++) {
for (int j = y; j < y + length; j++) {
if (i == x + 1 && j == y + 1) map[i][j] = ' ';
else map[i][j] = '*';
}
}
}
// recursion
int newLength = length/3;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (i == 1 && j == 1) {
printSpace(x + newLength * i, y + newLength * j, newLength);
} else {
func(x + newLength * i, y + newLength * j, newLength);
}
}
}
}
static void printSpace(int x, int y, int length) {
if (length == 1) return;
for (int i = x; i < x + length; i++) {
for (int j = y; j < y + length; j++) {
map[i][j] = ' ';
}
}
}
}
|
cs |
- 재귀
- 다른 사람들 풀이보다 길고 돌아서 푼거 같지만 나름 만족 ...
'PS > boj' 카테고리의 다른 글
boj)15649 - N과 M (1) (0) | 2020.11.16 |
---|---|
boj)5904 - Moo 게임 (0) | 2020.11.15 |
boj)16505 - 별 (0) | 2020.11.14 |
boj)1992 - 쿼드트리 (0) | 2020.11.13 |
boj)1780 - 종이의 개수 (0) | 2020.11.13 |
링크
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- HTTP 완벽 가이드
- java
- 패스트캠퍼스 컴퓨터공학 완주반
- REST API
- http
- 킹수빈닷컴
- js promise
- 이펙티브자바
- ㅇㄷㅇㅈ
- 이펙티브자바 아이템59
- 드림코딩
- dreamcoding
- 김영한 JPA
- 프로그래머스
- 백준
- 모던자바스크립트
- 가상 면접 사례로 배우는 대규모 시스템 설계 기초
- 이펙티브자바 아이템60
- JPA 연관관계 매핑
- js array
- Spring Security
- BOJ
- js api
- 백기선 스터디
- 이펙티브자바 스터디
- JS 딥다이브
- 프로그래머스 SQL
- HTTP 완벽가이드
- GCP
- 김영한 http
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
글 보관함