汽水瓶

65 阅读1分钟

image.png

image.png

// 从标准输入读取数据
const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

// 处理输入数据
function calculateMaxSodasCount(n) {
    let total = 0;

    // while (n >= 3) {
    //   const exchanged = Math.floor(n / 3) // 用空瓶可以兑换的汽水
    //   total += exchanged // 统计喝到的汽水数
    //   n = (n % 3) + exchanged // 更新剩余的空瓶数
    // }

    // if (n === 2) {
    //   total++ // 最后两个空瓶可以借一个汽水并喝掉
    // }
    total = Math.floor(n / 2)


    return total;
}

// 处理多组测试数据
function handleTestData() {
    rl.on("line", (input) => {
        const n = parseInt(input);
        if (n === 0) {
            // 输入结束,关闭读取流
            rl.close();
        } else {
            // 计算最多可以喝的汽水瓶数,并输出结果
            const maxSodasCount = calculateMaxSodasCount(n);
            console.log(maxSodasCount);
        }
    });
}

// 开始处理测试数据
handleTestData();

牛客网 - 找工作神器|笔试题库|面试经验|实习招聘内推,求职就业一站解决_牛客网 (nowcoder.com)