[파이썬][백준 2438번] 별 찍기 - 1
1. 문제Permalink
[Bronze III] 별 찍기 - 1 - 2438Permalink
성능 요약Permalink
메모리: 30864 KB, 시간: 76 ms
분류Permalink
구현(implementation)
문제 설명Permalink
첫째 줄에는 별 1개, 둘째 줄에는 별 2개, N번째 줄에는 별 N개를 찍는 문제
입력Permalink
첫째 줄에 N(1 ≤ N ≤ 100)이 주어진다.
출력Permalink
첫째 줄부터 N번째 줄까지 차례대로 별을 출력한다.
출처: 백준, https://https://www.acmicpc.net/
2. 해결방법 시간복잡도Permalink
- 단순 코딩 O(N)
3. 문제 해결 및 코드Permalink
This file contains hidden or 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 | |
N = int(sys.stdin.readline()) | |
for i in range(1, N + 1): | |
print(i * "*") |
-
주석을 참고하면서 이해를 돕습니다.Permalink
4. 알고리즘 및 해설Permalink
- 반복문을 1부터 해당 값까지 돌아가게 만든다.
- 별을 찍기 위해서는 정수 1부터 해야 별이 찍히기 때문이다.
- 반복문이 돌아가는 동안 돌아간 횟수 * 별을 출력해준다.