You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
721 B
25 lines
721 B
#include <iostream>
|
|
//题目:输入某年某月某日,判断这一天是这一年的第几天?
|
|
using namespace std;
|
|
int months_1[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
|
int months_2[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
|
|
|
bool LeapYear(int year) {
|
|
return ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0);
|
|
}
|
|
|
|
int main() {
|
|
int y, m, d, days = 0;
|
|
cin >> y >> m >> d;
|
|
if (LeapYear(y)) {
|
|
for (int i = 1; i <= m - 1; i++)
|
|
days += months_2[i];
|
|
days += d;
|
|
} else {
|
|
for (int i = 1; i <= m - 1; i++)
|
|
days += months_1[i];
|
|
days += d;
|
|
}
|
|
cout << days << endl;
|
|
return 0;
|
|
} |