import Foundation
/// ๋ถํดํฉ : N + (N์ ๊ฐ ์๋ฆฌ์์ ํฉ)
/// M : M์ ๋ถํดํฉ์ด N์ธ ๊ฒฝ์ฐ 'N์ ์์ฑ์' ๋ผ๊ณ ํจ
/// ์์ฐ์ N์ด ์ฃผ์ด์ง ๋ N์ ๊ฐ์ฅ ์์ ์์ฑ์๋ฅผ ๊ตฌํด๋ผ.
let N = Int(readLine()!)!
var arr = [Int]()
for M in 1...N {
if M.decomposition == N {
arr.append(M)
}
}
print(arr.min() ?? 0)
extension Int {
var decomposition: Int {
var num = self
var sum = num
while true {
if num < 10 {
sum += num
break
} else {
sum += num % 10
num = num / 10
}
}
return sum
}
}
ํ์ฅ์ผ๋ก ๋ถํดํฉ ๊ตฌํ๋ ์ ๋ง๋ ๋ค์ ๋ฐ๋ณต๋ฌธ ๋๋ ธ๋ค.
๋ฐ์ํ
'๐ ์ฝํ > BOJ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Swift] ๋ฐฑ์ค2775 (0) | 2023.03.27 |
---|---|
[Swift] ๋ฐฑ์ค2609 (0) | 2023.03.27 |
[Swift] ๋ฐฑ์ค2164 (0) | 2023.03.24 |
[Swift] ๋ฐฑ์ค1966 (0) | 2023.03.24 |
[Swift] ๋ฐฑ์ค1436 (0) | 2023.03.23 |