题解 | #三角形判断#

三角形判断

http://www.nowcoder.com/practice/689ec1e742394e09b1059556fc167b65

let line;
while ((line = readline())) {
  let strs = line.split(" ").map(Number);
  strs.sort((a, b) => a - b);
  if (strs[0] + strs[1] <= strs[2]) {
    //不能构成三角形
    console.info("Not a triangle!");
  } else if (strs[0] == strs[1] && strs[1] == strs[2]) {
    //等边三角形
    console.info("Equilateral triangle!");
  } else if (strs[0] == strs[1] || strs[1] == strs[2]) {
    //等腰三角形
    console.info("Isosceles triangle!");
  } else {
    //普通三角形
    console.info("Ordinary triangle!");
  }
}

全部评论

相关推荐

求offer的大角牛:不吃香菜
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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