题解 | #扑克牌大小#

扑克牌大小

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

const readline = require("readline");

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});
rl.on("line", function (line) {
  console.log(compare(line));
});
function compare(line) {
  const tokens = line.split("-");
  const cards = "3 4 5 6 7 8 9 10 J Q K A 2 joker JOKER";
  if (line.includes("joker JOKER")) return "joker JOKER";
  let one = tokens[0].split(" "),
    two = tokens[1].split(" ");
  if (one.length === two.length) {
    return cards.indexOf(one[0]) > cards.indexOf(two[0]) ? tokens[0] : tokens[1];
  } else if (one.length === 4) {
    return tokens[0];
  } else if (two.length === 4) {
    return tokens[1];
  } else {
    return "ERROR";
  }
}

全部评论

相关推荐

仁者伍敌:牛子这些人还会点一个自动回复,boss都不带回复的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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