题解 | #计算日期到天数转换#
计算日期到天数转换
https://www.nowcoder.com/practice/769d45d455fe40b385ba32f97e7bcded
1.判断闰年
2.数组保存平年,闰年11月份天数
3.计算天数的前面月份天数加当月天数
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 arr=[0,0,31,59,90,120,151,181,212,243,273,304,334]
//润年
let arr2=[0,0,31,60,91,121,152,182,213,244,274,305,335]
let tokens = line.split(' ');
let year = parseInt(tokens[0]);
let month = parseInt(tokens[1]);
let day = parseInt(tokens[2]);
let res = 0;
if(isLeapYear(year)){
res =arr2[month]+parseInt(day)
}else {
res =arr[month]+parseInt(day)
}
console.log(res)
}
}()
function isLeapYear(num){
if(num%4==0 &&num%100!=0 || num%400 == 0){
return 1
}
return 0
}