题解 | #汽水瓶#

汽水瓶

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

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
rl.on('line', function (line) {
    const emptyBottolesCount = parseInt(line);
    if (emptyBottolesCount === 0) return

    console.log(getDrinkCount(emptyBottolesCount, 0))
});

const getDrinkCount = (emptyCount, fillCount) => {
    if (emptyCount >= 3) {
        return getDrinkCount(emptyCount - 3 + 1, fillCount + 1)
    } else if (emptyCount === 2) {
        return fillCount + 1
    } else return fillCount
}

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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