题解 | #汽水瓶#
汽水瓶
https://www.nowcoder.com/practice/fe298c55694f4ed39e256170ff2c205f
const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;
void async function () {
// Write your code here
while ((line = await readline())) {
let list = [];
list.push(parseInt(line));
for (let index = 0; index < 9; index++) {
let count = parseInt(await readline());
if (count === 0) {
break;
}
list.push(count);
}
let result = []
list.forEach(item => {
let drinkCount = 0;// 喝的饮料数
while (item >= 3) {
let changeBottles = parseInt(item / 3);// 能换的饮料数
let otherBottoles = item % 3;// 每次兑换剩下的瓶子数
drinkCount += changeBottles;
item = changeBottles + otherBottoles;
}
if (item === 2) {
drinkCount ++;
}
result.push(drinkCount);
})
for (const item of result) {
console.log(item);
}
}
}()

