题解 | #扑克牌大小#

扑克牌大小

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

const d = { 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9, 10: 10, J: 11, Q: 12, K: 13, A: 14, 2: 15, joker: 16, JOKER: 17 }
function compareCard(s1, s2) {
  const a = s1.split(' ')
  const b = s2.split(' ')
  const n1 = a.length
  const n2 = b.length
  if (s1 === 'joker JOKER' || s2 === 'joker JOKER') {
    console.log('joker JOKER')
    return
  }
  if (n1 === n2) {
    // 相同类型的比较牌面大小
    if (d[a[0]] > d[b[0]]) {
      console.log(s1)
    } else {
      console.log(s2)
    }
  } else {
    // 炸弹和其他类型相比:输出炸弹
    if (n1 === 4) {
      console.log(s1)
    } else if (n2 === 4) {
      console.log(s2)
    } else {
      // 除了炸弹和对王,长度不同不存在比较关系
      console.log('ERROR')
    }
  }
}
var [s1, s2] = readline().split('-')
compareCard(s1, s2)
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务