-
Notifications
You must be signed in to change notification settings - Fork 106
/
Copy path2.6.cpp
34 lines (29 loc) · 983 Bytes
/
2.6.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
* 题目名称:今年的第几天?
* 题目来源:清华大学复试上机题
* 题目链接:http://t.cn/E9jXK5A
* 代码作者:杨泽邦(炉灰)
*/
#include <iostream>
#include <cstdio>
using namespace std;
int dayTable[2][13] = { //预处理
{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
};
bool IsLeapYear(int year) { //判断是否为闰年
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}
int main() {
int year, month, day;
while (scanf("%d%d%d", &year, &month, &day) != EOF) {
int number = 0; //记录天数
int row = IsLeapYear(year); //判断用哪一行
for (int j = 0; j < month; ++j) { //逐月添加天数
number += dayTable[row][j];
}
number += day;
printf("%d\n", number);
}
return 0;
}