문제 링크 (opens new window)

# 풀이

import Foundation

var input: [Int] = []

for _ in 0..<9 {
    input.append(Int(readLine()!)!)
}

func combination<T>(_ elements: [T], _ k: Int) -> [[T]] {
    var result: [[T]] = []

    func combi(_ index: Int, _ now: [T]) {
        if now.count == k {
            result.append(now)
            return
        }

        for i in index..<elements.count {
            combi(i + 1, now + [elements[i]])
        }
    }

    combi(0, [])
    return result
}

let arr = combination(input, 7)

func checkSum(_ arr: [Int]) -> Bool {
    var sum = 0
    for value in arr {
        sum += value
    }

    return sum == 100 ? true : false
}

func printSolution(_ arr: [Int]) {
    for value in arr.sorted() {
        print(value, " ")
    }
}

func solution(_ arr: [[Int]]) {
    for subArr in arr {
        if checkSum(subArr) {
            printSolution(subArr)
            return
        }
    }
}

solution(arr)