#include <stdio.h>
int days[13] =
{[1] = 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
struct date {
int year;
int mon;
int day;
};
struct date getdate(struct date start, int pass)
{
struct date tmp;
int s;
for (tmp.year = start.year, tmp.mon = start.mon, tmp.day = start.day + pass; tmp.day >= days[tmp.mon];
s = tmp.day, tmp.day -= days[tmp.mon], tmp.year += (tmp.mon + 1) / 13, tmp.mon = tmp.mon % 12 + 1)
tmp.mon == 2 && !(tmp.year % 4 == 0 && tmp.year % 100 != 0 || tmp.year % 400 == 0) && tmp.day > 28 && tmp.day++;
if (tmp.day == 0) {
tmp.day = s;
tmp.mon--;
}
return tmp;
}
int main(void)
{
struct date start;
int pass;
scanf("%d%d%d%d", &start.year, &start.mon, &start.day, &pass);
start = getdate(start, pass);
printf("%d-%d-%d\n", start.year, start.mon, start.day);
return 0;
}
计算给定日期后N天的日期
最新推荐文章于 2023-04-05 16:11:40 发布