티스토리 뷰
문제 링크
https://www.acmicpc.net/problem/10994
10994번: 별 찍기 - 19
예제를 보고 규칙을 유추한 뒤에 별을 찍어 보세요.
www.acmicpc.net
구현 코드
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
char Map[401][401]; | |
void draw_stars(int depth, int idx){ | |
if(depth == 1){ | |
Map[idx][idx] = '*'; | |
return; | |
} | |
int len = 4 * (depth - 1) + 1; | |
for(int i=idx;i<len+idx;i++){ | |
Map[idx][i] = '*'; | |
Map[idx + len - 1][i] = '*'; | |
} | |
for(int i=idx;i<len+idx;i++){ | |
Map[i][idx] = '*'; | |
Map[i][idx + len - 1] = '*'; | |
} | |
draw_stars(depth-1, idx+2); | |
return; | |
} | |
int main(){ | |
int n; | |
cin >> n; | |
int len = 4 * (n - 1) + 1; | |
for(int i=0;i<len;i++) | |
for(int j=0;j<len;j++) | |
Map[i][j] = ' '; | |
draw_stars(n,0); | |
for(int i=0;i<len;i++){ | |
for(int j=0;j<len;j++){ | |
cout << Map[i][j]; | |
} | |
cout << endl; | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def draw_stars(depth, idx): | |
if depth == 1: | |
Map[idx][idx] = '*' | |
return | |
l = 4 * (depth - 1) + 1 | |
for i in range(idx, l+idx): | |
Map[idx][i] = '*' | |
Map[idx+l-1][i] = '*' | |
for i in range(idx, l+idx): | |
Map[i][idx] = '*' | |
Map[i][idx+l-1] = '*' | |
draw_stars(depth-1, idx+2) | |
return | |
n = int(input()) | |
length = 4 * (n - 1) + 1 | |
Map = [[' '] * length for _ in range(length)] | |
draw_stars(n,0) | |
for i in range(length): | |
for j in range(length): | |
print(Map[i][j], end="") | |
print() |
'Coding Test > 백준' 카테고리의 다른 글
[C++/Python] 백준 10996 - 별찍기 - 21 (0) | 2020.07.15 |
---|---|
[C++/Python] 백준 10995 - 별찍기 - 20 (0) | 2020.07.14 |
[C++/Python] 백준 10993 - 별찍기 - 18 (0) | 2020.07.12 |
[C++/Python] 백준 10992 - 별찍기 - 17 (0) | 2020.07.11 |
[C++/Python] 백준 10991 - 별찍기 - 16 (0) | 2020.07.10 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 완전탐색
- Sqoop
- HiveQL
- pyspark
- 배열과 문자열
- 하둡
- 출전 순서 정하기
- Django
- Hadoop
- 합친 lis
- C++
- 종만북
- microwaving lunch boxes
- 알고스팟
- 삼각형 위의 최대 경로
- 두니발 박사의 탈옥
- 삼각형 위의 최대 경로 수 세기
- hive
- Jaeha's Safe
- python
- 하이브
- HDFS
- import
- 코딩인터뷰 완전분석
- 백준
- 팰린드롬 구하기
- 외발 뛰기
- 스파크
- 2225
- 분할정복
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함