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