Topic link: http://acm.hdu.edu.cn/showproblem.php?pid=2005
What day?
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 177873 Accepted Submission(s): 63023
Problem Description
Given a date, output the day of the year the date is.
Input
There are multiple groups of input data, each group occupies one line, and the data format is YYYY/MM/DD. For details, please refer to sample input. In addition, you can ensure that all input data are legal.
Output
For each set of input data, output a row indicating the day of the year the date is.
Sample Input
1985/1/20
2006/3/12
Sample Output
20
71
#include <stdio.h> int leapyear_day(int year, int month) { // do not need to add 1 day to January or February, add 1 day to other months, and add 1 day to non-money if (month <= 2 ) return 0 ; else return (((year % 4 == 0 ) && (year % 100 != 0 )) || (year % 400 == 0 )) ? 1 : 0 ; } int main(void) { int year, month, day; int days; int monthsum[] = { // The number of days to a certain month, plus the number of days to run the year 0 // January , 31 // February , 31 + 28 // March , 31 + 28 + 31 // April , 31 + 28 + 31 + 30 // May , 31 + 28 + 31 + 30 +31 // June , 31 + 28 + 31 + 30 + 31 + 30 // July , 31 + 28 + 31 + 30 + 31 + 30 + 31 // August , 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 // September ,31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 // October , 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 // November , 31 + 28 + 31 + 30 + 31 + 30 +31 + 31 + 30 + 31 + 30 // December }; while (scanf( " %d/%d/%d " , &year, &month, &day) != EOF) { // The number of days = the number of days to be added to the year (calculated according to the year and month) + the number of days to a certain month + the month Inner days days = leapyear_day(year, month) + monthsum[month - 1 ] + day; // output result printf( " %d\n " , days); } return 0; }
2018-04-23