Submission
Status:
----------P--------P
Score: 10
User: tankunkid
Problemset: ปฏิทินวันแม่
Language: c
Time: 0.001 second
Submitted On: 2024-09-26 14:21:12
#include <stdio.h>
int main() {
int m, d, sumd = 0;
scanf("%d", &m);
scanf("%d", &d);
// Days in each month
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
// Fixed date for Mother's Day (August 12)
int momm = 8; // August
int momd = 12; // 12th day of August
// Case 1: If the input month is after August (momm)
if (m > momm) {
for (int i = momm; i < m - 1; i++) {
sumd += month[i]; // Sum days between months
}
sumd += month[momm - 1] - momd; // Days left in August after 12th
sumd += d; // Add the days in the target month
}
// Case 2: If the input month is before August
else if (m < momm) {
for (int i = m; i < momm - 1; i++) {
sumd += month[i]; // Sum days between months
}
sumd += month[m - 1] - d; // Remaining days in the input month
sumd += momd; // Add days up to the 12th in August
}
// Case 3: If the input month is August itself
else {
if (d > momd) {
sumd += d - momd; // If the input day is after the 12th
} else {
sumd += momd - d; // If the input day is before the 12th
}
}
// Determine the weekday of Mother's Day (August 12)
int mother_day_of_week = 6; // August 12 is Saturday (6th day of the week)
// Adjust for positive and negative offsets in days
int result_day_of_week = (mother_day_of_week + sumd) % 7;
if (result_day_of_week <= 0) {
result_day_of_week += 7;
}
// Print the resulting weekday
printf("%d", result_day_of_week);
return 0;
}