Submission

Status:

PPPPPPPPTPPPPPPPPPPP

Subtask/Task Score:

95/100

Score: 95

User: mik

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

Language: cpp

Time: 1.084 second

Submitted On: 2026-10-10 18:28:48

#include <bits/stdc++.h>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false),cin.tie(NULL);
    
    // จำนวนวันในแต่ละเดือน (เดือน 1 ถึง 12)
    int days_in_month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    
    int m, d;
    cin >> m >> d;
    
    int current_m = m;
    int current_d = 1;
    
    int target_m = 8;
    int target_d = 12;
    
    int day_counter = 0;
    
    // ถ้าเดือนปัจจุบันน้อยกว่าเดือนสิงหาคม ให้เดินหน้าไปหา 12 สิงหาคม
    if (m < 8) {
        while (!(current_m == target_m && current_d == target_d)) {
            current_d++;
            day_counter++;
            if (current_d > days_in_month[current_m]) {
                current_d = 1;
                current_m++;
            }
        }
        int day = (d - 1 + day_counter) % 7 + 1;
        cout << day;
    } 
    // ถ้าเดือนปัจจุบันมากกว่าหรือเท่ากับเดือนสิงหาคม ให้ถอยหลังหรือเดินหน้าตามจริง
    else {
        // ใช้การคำนวณวันสะสมจาก 12 สิงหาคม ย้อนกลับไป หรือเดินหน้า
        // เพื่อความง่ายและแม่นยำ สามารถคำนวณผลต่างวันตรงๆ ได้เช่นกัน
        // แต่ถ้า m >= 8 ลองใช้ลูปจำลองย้อนกลับหรือเดินหน้าได้ครับ
        while (!(current_m == target_m && current_d == target_d)) {
            current_d--;
            day_counter++;
            if (current_d < 1) {
                current_m--;
                current_d = days_in_month[current_m];
            }
        }
        // ถ้า m อยู่หลังสิงหาคม วันที่ 1 ของเดือน m จะอยู่ "หลังจาก" 12 สิงหาคม
        int day = (d - 1 - day_counter) % 7;
        while (day < 0) day += 7;
        cout << day + 1;
    }
    
    return 0;
}