Submission
Status:
PPPPPPPPPP
Score: 100
User: Pera
Problemset: E.Comet
Language: c
Time: 0.002 second
Submitted On: 2024-10-14 18:40:55
#include <stdio.h>
// Check leap year
// calculate remaining days in that month
// if remaining days is more than t, remove it from t and move on to the next month
// if remaining days is less than t, add it to d and print day, if the day is max of that month move on to the first of next month
int isleap(int year) {
if (year % 4 == 0 && year % 100 != 0) return 1;
if (year % 400 == 0) return 1;
return 0;
}
int main(void) {
int d, m, y, t, n;
scanf("%d %d %d", &d, &m, &y);
scanf("%d", &t);
scanf("%d", &n);
t *= n;
int daysinleap[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int daysnotinleap[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
while (t > 0) {
if (isleap(y)) {
int daysleftinmonth = daysinleap[m - 1] - d + 1;
if (t > daysleftinmonth) {
t -= daysleftinmonth;
d = 1;
m++;
if (m > 12) {
m = 1;
y++;
}
} else {
//printf("Days left in month is %d\n", daysleftinmonth);
//printf("t before adding is %d and d before adding is %d\n", t, d);
d += t;
//printf("t is %d and d is %d\n", t, d);
t = 0;
if (d > daysinleap[m - 1]) {
//printf("HERE!\n");
d = 1;
m++;
if (m > 12) {
m = 1;
y++;
}
}
}
} else {
int daysleftinmonth = daysnotinleap[m - 1] - d + 1;
if (t > daysleftinmonth) {
t -= daysleftinmonth;
d = 1;
m++;
if (m > 12) {
m = 1;
y++;
}
} else {
d += t;
t = 0;
if (d > daysnotinleap[m - 1]) {
d = 1;
m++;
if (m > 12) {
m = 1;
y++;
}
}
}
}
}
printf("%d %d %d\n", d, m, y);
}