1 cc.Class({ 2 extends: cc.Component, 3 4 properties: { 5 }, 6 7 // LIFE-CYCLE CALLBACKS: 8 9 onLoad () { 10 for (let index = 8; index < 1001; index++){ 11 this.init(index, 4); 12 } 13 }, 14 15 // people为人数 16 // num为几个瓶子换一瓶饮料 17 init(people, num) { 18 let d = people % num; //取余数,不能取整,则表示多出来多少人 19 let temp = Math.floor(people / num); //向下取整,余数已经计算过,在此忽略余数的影响 20 let total = temp * (num - 1) + d; 21 console.log(people,"个人,至少需要:", total + ",瓶饮料"); 22 }, 23 24 start () { 25 26 }, 27 28 // update (dt) {}, 29 });
原文:https://www.cnblogs.com/Hunter-541695/p/14925206.html