题解 | #统计每个月兔子的总数#
统计每个月兔子的总数
https://www.nowcoder.com/practice/1221ec77125d4370833fd3ad5ba72395
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
let total = 1;
let childenBirthMonth = []
const getChildren = (birthMonth, month) => {
for (let i = birthMonth; i <= month; i++) {
if (i - birthMonth >= 2) {
total++;
childenBirthMonth.push(i);
}
}
}
rl.on('line', function (line) {
const month = parseInt(line);
getChildren(1, month);
for (let i = 0; i < childenBirthMonth.length; i++) {
getChildren(childenBirthMonth[i], month);
}
console.log(total);
});