题解 | #扑克牌大小#

扑克牌大小

http://www.nowcoder.com/practice/d290db02bacc4c40965ac31d16b1c3eb

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)
        }
    }

}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务