Swift题解

while let str = readLine() {
    let array = str.components(separatedBy: "-")
    let s1 = array[0]
    let s2 = array[1]
    let c1 = s1.components(separatedBy: " ").count
    let c2 = s2.components(separatedBy: " ").count
    let bigBoom = "joker JOKER"
    if c1 != c2 {
        if s1 == bigBoom || s2 == bigBoom {
            print(bigBoom)
        } else if c1 == 4 {
            print(s1)
        } else if c2 == 4 {
            print(s2)
        } else {
            print("ERROR")
        }
    } else {
        let map = ["3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2", "joker", "JOKER"]
        let f1 = s1.components(separatedBy: " ")[0]
        let f2 = s2.components(separatedBy: " ")[0]
        let index1 = map.firstIndex(where: { f1 == $0 })!
        let index2 = map.firstIndex(where: { f2 == $0 })!
        if index1 > index2 {
            print(s1)
        } else {
            print(s2)
        }
    }

}