华为机试-计算日期到天数转换(HJ73)-纯C
计算日期到天数转换
http://www.nowcoder.com/questionTerminal/769d45d455fe40b385ba32f97e7bcded
纯C
#include <stdlib.h> #include <stdio.h> int main() { int month_days[12] = {31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365}; int year, month, day; while(scanf("%d %d %d\n", &year, &month, &day) != EOF) { int days = 0; if(month >= 2) days = month_days[month - 2] + day; else days = day; if((year%4 == 0 && year%100 != 0) || year %400 == 0) days ++; printf("%d\n", days); } return 0; }