【JavaScript】7-9 用天平找小球 (10分)

题目:

三个球A、B、C,大小形状相同且其中有一个球与其他球重量不同。要求找出这个不一样的球。

输入格式:

输入在一行中给出3个正整数,顺序对应球A、B、C的重量。

输出格式:

在一行中输出唯一的那个不一样的球。

输入样例:

1 1 2

输出样例:

C

JavaScript代码:

const { parse } = require('path')
var readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})

rl.on('line', function(line) {
    var tokens = line.split(" ")  //以空格分隔字符串为字符串数组
    var x = parseInt(tokens[0])
    var y = parseInt(tokens[1])
    var z = parseInt(tokens[2])
    var ret = ball(x,y,z)
    console.log(ret)
})

function ball(x,y,z){
    var s = new String()
    if(x == y) {
        s = "C"
    } else if(x !=y && x == z) {
        s = "B"
    } else {
        s = "A"
    }
    return s

}
原文地址:https://www.cnblogs.com/moonskies/p/14313128.html