[1759] 암호 만들기

toru·2022년 9월 17일
0
let p = readLine()!.split(separator: " ").map{Int(String($0))!}
let (end,n) = (p[0],p[1])
let char = readLine()!.split(separator: " ").map{String($0)}.sorted()
let vowels:Set<Character> = ["a","i","u","e","o"]

func dfs(_ idx:Int,_ depth:Int,_ str:String) {
    if depth == end {
        var v = false
        var c = 0        
        for i in str {
            if vowels.contains(i) {
                v = true
            } else {
                c += 1
            }
        }
        if v, 2<=c {
            print(str)
        }
        return
    }
    for i in idx..<n {
        dfs(i+1, depth+1, str+char[i])
    }
}
dfs(0, 0, "")
profile
iOS

0개의 댓글