Swift) 백준 6603 로또 - S2

https://www.acmicpc.net/problem/6603

 

6603번: 로또

입력은 여러 개의 테스트 케이스로 이루어져 있다. 각 테스트 케이스는 한 줄로 이루어져 있다. 첫 번째 수는 k (6 < k < 13)이고, 다음 k개 수는 집합 S에 포함되는 수이다. S의 원소는 오름차순으로

www.acmicpc.net

순서와 상관없이 들어가 있는 숫자가 동일하지 않는 수열을 출력하는 문제. N과 M 문제를 풀었다면 쉽게 풀만한 문제

 

import Foundation

while true {
    
    var inputArr = readLine()!.split(separator: " ").map{ Int($0)! }
    
    if inputArr[0] == 0 {
        break
    }
    var input = inputArr
    input.removeFirst()
    input.sort()
    var numArr = Array(repeating: 0, count: 6)
    
    func dfs(at: Int, depth: Int) {
        if depth == 6 {
            print(numArr.map{ String($0) }.joined(separator: " "))
            return
        }
        for item in at..<input.count {
            numArr[depth] = input[item]
            dfs(at: item+1, depth: depth+1)
        }
    }
        dfs(at: 0, depth: 0)
   print("")
}