Submission

Status:
PPPPPPPPP----PP-PPPP

Score: 75

User: www._.

Problemset: ปฏิทินวันแม่

Language: cpp

Time: 0.003 second

Submitted On: 2025-01-12 08:48:48

#include <iostream>
using namespace std;

int main() {
    int m, d; // Starting month and starting day of the week (1 = Monday, 7 = Sunday)
    int dtillmd = 0;
    int targetmonth = 8; // Mother's Day month
    int targetday = 12;  // Mother's Day day
    int numdays[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; // Days in each month

    // Input starting month and starting day of the week
    //cout << "Enter the starting month (1-12): ";
    cin >> m;
    //cout << "Enter the starting day of the week for the first day of the starting month (1 = Monday, 7 = Sunday): ";
    cin >> d;

    // Calculate days from the starting date to the target date
    for (int i = m; i <= targetmonth - 1; i++) {
        dtillmd += numdays[i - 1]; // Add full months
    }
    dtillmd += targetday; // Add target day 

    // Determine the day of the week for Mother's Day
    int mothers_day_weekday = (d + dtillmd - 1) % 7; // Align the weekday calculation
    if (mothers_day_weekday == 0) {
        mothers_day_weekday = 7; // Wrap around Sunday
    }

    // Output total days until Mother's Day
    cout  << mothers_day_weekday  << endl;

    // Output the day of the week for Mother's Day
    //string weekdays[] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
    //out << "Mother's Day falls on a: " << weekdays[mothers_day_weekday - 1] << endl;

    return 0;
}