๋ฐ์ํ
์ง๊ฐ์ผ๊ฐํ ์ถ๋ ฅํ๊ธฐ
๋ฌธ์ ์ค๋ช
"*"์ ๋์ด์ ๋๋น๋ฅผ 1์ด๋ผ๊ณ ํ์ ๋, "*"์ ์ด์ฉํด ์ง๊ฐ ์ด๋ฑ๋ณ ์ผ๊ฐํ์ ๊ทธ๋ฆฌ๋ ค๊ณ ํฉ๋๋ค. ์ ์ n ์ด ์ฃผ์ด์ง๋ฉด ๋์ด์ ๋๋น๊ฐ n ์ธ ์ง๊ฐ ์ด๋ฑ๋ณ ์ผ๊ฐํ์ ์ถ๋ ฅํ๋๋ก ์ฝ๋๋ฅผ ์์ฑํด๋ณด์ธ์.
์ ํ ์ฌํญ
- 1 ≤ n ≤ 10
์ ์ถ๋ ฅ ์
์ ๋ ฅ | ์ถ๋ ฅ |
3 | * ** *** |
์ ์ถ๋ ฅ ์ ์ค๋ช
์ ์ถ๋ ฅ ์ #1
- n์ด 3์ด๋ฏ๋ก ์ฒซ์งธ ์ค์ * 1๊ฐ, ๋์งธ ์ค์ * 2๊ฐ, ์ ์งธ ์ค์ * 3๊ฐ๋ฅผ ์ถ๋ ฅํฉ๋๋ค.
์ ์ถ
import Foundation
let n = readLine()!.components(separatedBy: [" "]).map { Int($0)! }
for i in 0..<n[0]{
for j in 0..<i+1{
print("*", terminator: "")
}
print("")
}
์ด์ค for๋ฌธ์ ์ฌ์ฉํ์ฌ * ์ถ๋ ฅ
ํ ์ค์ ํํํ๊ธฐ์ํด print( , terminator:"") ์ฌ์ฉ
๋ค๋ฅธ ํ์ด
import Foundation
let n = readLine()!.components(separatedBy: [" "]).map { Int($0)! }
let length = n.first!
for i in (1...length) {
print(String(repeating: "*", count: i))
}
for๋ฌธ์ ํ๋ฒ๋ง ์ฌ์ฉํ์ฌ * ์ถ๋ ฅ
String(repeating, count)๋ฅผ ์ฌ์ฉ
๋ฐ์ํ
'โจ๏ธ Language > swift' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค LV.0] ๋ฌธ์ ๋ฐ๋ณต ์ถ๋ ฅํ๊ธฐ (0) | 2022.12.13 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค LV.0] ์ง์ ํ์ ๊ฐ์ (0) | 2022.12.06 |
[Swift] ํ๋ก๊ทธ๋๋จธ์ค LV.0 ๋ฌธ์์ด ๋ค์ง๊ธฐ (0) | 2022.12.06 |
[Swift] ํ๋ก๊ทธ๋๋จธ์ค LV.0 ๋ฐฐ์ด ๋ค์ง๊ธฐ (0) | 2022.12.05 |
[Swift] ํ๋ก๊ทธ๋๋จธ์ค LV.0 ๋์ด ์ถ๋ ฅ (0) | 2022.12.05 |