题解 | #汽水瓶#

汽水瓶

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);
    }
  }
}()

全部评论

相关推荐

不知道怎么取名字_:两个方向 1.简历针对性准备下 2.面试前也需要准备的 主要还是要看各个公司需求,看公司行业和岗位描述,那里面已经写了对技术的需求,一份简历,不可能和所有嵌入式岗位都匹配的
投递北京经纬恒润科技股份有限公司等公司6个岗位
点赞 评论 收藏
分享
11-11 16:40
已编辑
门头沟学院 人工智能
不知道怎么取名字_:这个有点不合理了,相当于已经毕业了,但还是没转正,这不就是白嫖
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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