티스토리 뷰
문제 링크
https://www.acmicpc.net/problem/10997
10997번: 별 찍기 - 22
예제를 보고 규칙을 유추한 뒤에 별을 찍어 보세요.
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[500][500]; | |
void draw_stars(int depth, int idx){ | |
if(depth == 1){ | |
Map[idx][idx] = '*'; | |
Map[idx+1][idx] = '*'; | |
Map[idx+2][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+2;i++){ | |
Map[i][idx] = '*'; | |
Map[i][idx + len - 1] = '*'; | |
} | |
Map[idx+1][idx+len-1] = ' '; | |
Map[idx+2][idx+len-2] = '*'; | |
draw_stars(depth-1, idx+2); | |
return; | |
} | |
int main(){ | |
int n; | |
cin >> n; | |
if(n == 1){ | |
cout << '*' << endl; | |
return 0; | |
} | |
int len = 4 * (n - 1) + 1; | |
for(int i=0;i<len+2;i++) | |
for(int j=0;j<len;j++) | |
Map[i][j] = ' '; | |
draw_stars(n,0); | |
for(int i=0;i<len+2;i++){ | |
if(i == 1){ | |
cout << '*' << endl; | |
continue; | |
} | |
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
import sys | |
def draw_stars(depth, idx): | |
if depth == 1: | |
Map[idx][idx] = '*' | |
Map[idx+1][idx] = '*' | |
Map[idx+2][idx] = '*' | |
return | |
r = 4 * (depth - 1) + 1 | |
c = 4 * (depth - 1) + 3 | |
for i in range(idx, r+idx): | |
Map[idx][i] = '*' | |
Map[idx+r+1][i] = '*' | |
for i in range(idx, c+idx): | |
Map[i][idx] = '*' | |
Map[i][idx+r-1] = '*' | |
Map[idx+1][idx+r-1] = ' ' | |
Map[idx+2][idx+r-2] = '*' | |
draw_stars(depth-1, idx+2) | |
return | |
n = int(input()) | |
if n == 1: | |
print('*') | |
sys.exit() | |
row = 4 * (n - 1) + 1 | |
col = 4 * (n - 1) + 3 | |
Map = [[' '] * row for _ in range(col)] | |
draw_stars(n,0) | |
for i in range(col): | |
if i == 1: | |
print('*') | |
continue | |
for j in range(row): | |
print(Map[i][j], end="") | |
print("") |
'Coding Test > 백준' 카테고리의 다른 글
[C++/Python] 백준 1463 - 1로 만들기 (0) | 2020.07.20 |
---|---|
[C++/Python] 백준 13015 - 별찍기 - 23 (0) | 2020.07.17 |
[C++/Python] 백준 10996 - 별찍기 - 21 (0) | 2020.07.15 |
[C++/Python] 백준 10995 - 별찍기 - 20 (0) | 2020.07.14 |
[C++/Python] 백준 10994 - 별찍기 - 19 (0) | 2020.07.13 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 알고스팟
- microwaving lunch boxes
- hive
- HiveQL
- pyspark
- 종만북
- import
- 스파크
- 완전탐색
- 코딩인터뷰 완전분석
- 외발 뛰기
- Hadoop
- C++
- 두니발 박사의 탈옥
- 합친 lis
- Django
- Sqoop
- 하둡
- 삼각형 위의 최대 경로
- 삼각형 위의 최대 경로 수 세기
- 출전 순서 정하기
- python
- 2225
- 팰린드롬 구하기
- Jaeha's Safe
- 배열과 문자열
- 하이브
- 백준
- 분할정복
- HDFS
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함