[백준] 별찍기 7
2025. 1. 5. 00:20
정답
let n = Int(readLine()!)!
for i in 1...n {
let star = String(repeating: " ", count: n - i) + String(repeating: "*", count: 2 * i - 1)
print(star)
}
for i in 1..<n {
let star = String(repeating: " ", count: i) + String(repeating: "*", count: 2 * (n - i) - 1)
print(star)
}
String(repeating:count:)를 이용해서 풀이
init(repeating:count:) | Apple Developer Documentation
Creates a new string representing the given string repeated the specified number of times.
developer.apple.com
출처
만도스의 개발 일기장
dev-mandos.tistory.com
728x90
'Test > Coding Tests' 카테고리의 다른 글
[BaekJoon] 1316 그룹 단어 체커 (0) | 2025.02.01 |
---|---|
[Backjoon] 10810 공 넣기 (0) | 2024.11.10 |
[BaekJoon] 아스키 코드 - 11654번 (2) | 2024.10.13 |
[BaekJoon] A+B - 4 (0) | 2024.10.06 |
[BaekJoon] A+B - 5 (0) | 2024.10.06 |