๋ธŒ๋ก ์ฆˆ2 : ๋ธŒ๋ฃจํŠธํฌ์Šค ๋ฌธ์ œ์ด๋‹ค.

Code

import Foundation
 
func getGenerateNumber(of num: Int) -> Int {
    var ret = num
    let num = String(num)
    num.forEach { ret += Int(numericCast($0.unicodeScalars.first!.value) - 48) } // 0์€ ์•„์Šคํ‚ค์ฝ”๋“œ๋กœ 48
    return ret
}
 
func main() {
    let n = Int(readLine()!)!
    var result = [Int]()
    for i in 1...n {
        if getGenerateNumber(of: i) == n {
            result.append(i)
        }
    }
    print(result.isEmpty ? 0 : result.min()!)
}
 
main()
 

Code2

import sys
input = sys.stdin.readline
 
def get_generate_number(num):
    ret = num
    num = f"{num}"
    for char in num:
        ret += int(char)
    return ret
 
def main():
    n = int(input())
    result = []
    for i in range(1, n + 1):
        if get_generate_number(i) == n:
            result.append(i)
    print(min(result) if result else 0)
 
if __name__ == "__main__":
    main()

Reference