问题描述:
代码示例:
//计算第几天
#include <bits/stdc++.h>
using namespace std;int main(){cout << "输入样例" << endl; int year;int month;int day; cin >> year >> month >> day;int months1[12] = {31,28,31,30,31,30,31,31,30,31,30,31};int months2[12] = {31,29,31,30,31,30,31,31,30,31,30,31};int days = 0;// 判断是闰年还是平年if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0){for(int i = 0; i < month - 1; i++){days += months2[i];}days += day;}else{for(int i = 0; i < month - 1; i++){days += months1[i];}days += day;}cout << "输出样例" << endl; cout << days << endl;return 0;
}
运行结果: