์ฒ์์ ๋ ธํธ์ ์ด๋ฐ์์ผ๋ก ํ๋ค๊ฐ ์กฐํฉ์์ ๊ตฌํํ๋ ๊ณผ์ ์์ ์ซ์๊ฐ ๋๋ฌด์ปค์ ธ์ ๋ฐํ์ ์๋ฌ๊ฐ ๋ฐ์ํ๋ค.
import Foundation
let T = Int(readLine()!)!
for _ in 1...T {
let k = Int(readLine()!)!
let n = Int(readLine()!)!
print(getPeopleNum(floor: k, row: n))
}
func getPeopleNum(floor: Int, row: Int) -> Int {
if row == 1 {
return 1
}
if floor == 0 {
return row
}
return getPeopleNum(floor: floor - 1, row: row) + getPeopleNum(floor: floor, row: row - 1)
}
๊ทธ๋์ ์ฌ๊ทํจ์๋ก ์ ๊ทผํด์ ๋ค์ ํ์๋ค.
๋ฐ์ํ
'๐ ์ฝํ > BOJ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Swift] ๋ฐฑ์ค7568 ๋ฉ์น (0) | 2023.03.28 |
---|---|
[Swift] ๋ฐฑ์ค10773 (0) | 2023.03.27 |
[Swift] ๋ฐฑ์ค2609 (0) | 2023.03.27 |
[Swift] ๋ฐฑ์ค2231 (0) | 2023.03.24 |
[Swift] ๋ฐฑ์ค2164 (0) | 2023.03.24 |