小明每天都坚持写日记突然有一天小明在想我今年写了多少篇日记了?一篇一篇的数好麻烦没办法小明只能把这个艰难的问题交给聪明的你来解决。输入描述输入三个整数ymd分别表示年月日数据均在int范围内。输出描述输出一个整数表示这是今年的第几天。用例输入 1 2018 1 1用例输出 1 1用c++做
#include
bool isLeapYear(int year) { return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0); }
int main() { int year, month, day; cin >> year >> month >> day;
int totalDays = 0;
int daysInMonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if (isLeapYear(year)) {
daysInMonth[1] = 29;
}
for (int i = 0; i < month - 1; i++) {
totalDays += daysInMonth[i];
}
totalDays += day;
cout << totalDays << endl;
return 0;
原文地址: https://www.cveoy.top/t/topic/h8sV 著作权归作者所有。请勿转载和采集!