文章
13
粉丝
171
获赞
8
访问
46.6k
#include <iostream>
using namespace std;
int arr[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
void update(int year) {//更新每个月有多少天数组
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
arr[1] = 29;
} else {
arr[1] = 28;
}
}
int main() {
int m;
while (scanf("%d", &m) != EOF) {
for (int i = 0; i < m; i++) {
int year, month, day, n;
scanf("%d %d %d %d", &year, &month, &day, &n);
update(year);//先更新一下当前年份是平年还是闰年
for (int j = 0; j < n; j++) {
day++;//增加日期
if (day > arr[month - 1]) {//日期超出,增加月份
month++;
day = 1;
if (month > 12) {//月份超出,增加年份
year++;
month = 1;
update(year);//年份改变,平闰年可能改变,需要更新一下
}
}
...
登录后发布评论
暂无评论,来抢沙发