题解 | #计算日期到天数转换#
计算日期到天数转换
https://www.nowcoder.com/practice/769d45d455fe40b385ba32f97e7bcded
#include <stdio.h> int main() { int y = 0; int m = 0; int d = 0; int i = 0; int sum = 0; int arr[13] = { 0,31,29,31,30,31,30,31,31,30,31,30,31 }; int arr1[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 }; scanf("%d%d%d", &y, &m, &d); if (y % 4 == 0 && y % 100 != 0 || y % 400 == 0) { for (i = 0; i < m; i++) { sum += arr[i]; } printf("%d\n", sum+d); } else { for (i = 0; i < m; i++) { sum += arr1[i]; } printf("%d\n", sum+d); } return 0; }