题解 | #计算日期到天数转换#
计算日期到天数转换
https://www.nowcoder.com/practice/769d45d455fe40b385ba32f97e7bcded
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 let arr = []; let year; let month; let day; let result = 0; const md = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; while ((line = await readline())) { arr = line.split(" "); year = parseInt(arr[0]); month = parseInt(arr[1]); day = parseInt(arr[2]); } if (month == 1) { result = day; } else if (month == 2) { result = 31 + day; } else { // 3月及以上,2月先按平月28天算 for (let i = 1; i < month; i++) { result += md[i]; } result += day; } if (((year % 4 == 0 && year % 100) || year % 400 == 0) && month >= 3) { result += 1; } console.log(result); })();