题解 | #汽水瓶#
汽水瓶
http://www.nowcoder.com/practice/fe298c55694f4ed39e256170ff2c205f
先借一个来,反正手里总会剩一个的
while(n = Number(readline()) ) {
console.log(bottleCount(n))
}
function bottleCount(n) {
// 先借一个瓶子,用不用再说
let bottles = n + 1, drink = 0
while (bottles >= 3) {
drink += parseInt(bottles/3);
bottles = parseInt(bottles / 3) + parseInt(bottles % 3)
}
return drink
}