【題解】ZeroJudge e923: pB. ISO日曆系統(二)

【題目敘述】https://zerojudge.tw/ShowProblem?problemid=e923

#include <iostream>
using namespace std;
int N, W, M, D;
int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

void getWeek(int m, int d, int &wk, int &day){
    int delta = 0;
    if (W <= 4){
        delta = W + 5;
    } else {
        delta = W - 2;
    }
    int dd = 0;
    for (int i = 1; i < m; i++){
        dd += days[i];
    }
    dd += d;
    wk = (dd + delta) / 7;
    if (wk == 0) wk = -1;
    day = (dd + W - 1) % 7;
    if (day == 0) day = 7;
}
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> N;
    while (N--){
        cin >> W >> M >> D;
        int week, day;
        getWeek(M, D, week, day);
        cout << week << " " << day << "\n";
    }
    return 0;
}
分享本文 Share with friends