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