题解 | #求解立方根#

求解立方根

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

const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void (async function () {
    let num = 0;
    function cal(str) {
        str = Math.abs(str); //求绝对值
        if (num * num * num <= str) {
            num += 0.01;
            cal(str);
        } else {
            return num;
        }
    }
    while ((line = await readline())) {
        cal(line);
        console.log(line >= 0 ? num.toFixed(1): -num.toFixed(1))
    }
})();

全部评论

相关推荐

Twilight_m...:经典我朋友XXXX起手,这是那种经典的不知道目前行情搁那儿胡编乱造瞎指导的中年人,不用理这种**
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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