#include <stdio.h>
#include <stdlib.h>
typedef struct tm_ymd_641_t
{
int y;
int m;
int d;
} tm_ymd_641;
int leapyear(int year)
{
return (((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0)) ? 1 : 0);
}
int eom(const tm_ymd_641 date)
{
static const int daysinmonth[2][12] =
{
{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
};
return daysinmonth[leapyear(date.y)][date.m - 1];
}
int iseom(const tm_ymd_641 date)
{
return date.d == eom(date) ? 1 : 0;
}
int isvaliddate(const tm_ymd_641 date)
{
return 1 <= date.m && date.m <= 12 && 1 <= date.d && date.d <= eom(date) ? 1 : 0;
}
tm_ymd_641 parse_date(char date[])
{
tm_ymd_641 ymd_date;
ymd_date.
d = atoi(&date
[6]); date[6] = '\0';
ymd_date.
m = atoi(&date
[4]); date[4] = '\0';
return ymd_date;
}
int main(void)
{
char date[9];
tm_ymd_641 ymd;
ymd = parse_date(date);
if (!isvaliddate(ymd))
{
puts("Input date is invalid!"); }
if (iseom(ymd))
{
if (ymd.m == 12)
{
ymd.y++;
ymd.m = 1;
}
else
{
ymd.m++;
}
ymd.d = 1;
}
else
{
ymd.d++;
}
printf("Next day is %d/%d/%d\n", ymd.
y, ymd.
m, ymd.
d);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCnR5cGVkZWYgc3RydWN0IHRtX3ltZF82NDFfdAp7CglpbnQgeTsKCWludCBtOwoJaW50IGQ7Cn0gdG1feW1kXzY0MTsKCmludCBsZWFweWVhcihpbnQgeWVhcikKewoJcmV0dXJuICgoKHllYXIgJSA0ID09IDApICYmICh5ZWFyICUgMTAwICE9IDApIHx8ICh5ZWFyICUgNDAwID09IDApKSA/IDEgOiAwKTsKfQoKaW50IGVvbShjb25zdCB0bV95bWRfNjQxIGRhdGUpCnsKCXN0YXRpYyBjb25zdCBpbnQgZGF5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