Try   HackMD
tags: CPE-數學計算

A - Doom's Day Algorithm

題目:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

用總天數%7取餘數就會是星期幾了

Month[]中的0是初始值,讓Month可以配合實際月份,days+d+5中的+5是校正數值

#include <bits/stdc++.h>

using namespace std;

int main() {
    int kase;
    cin >> kase;
    string Day[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
    int Month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    while (kase--) {
        int m, d;
        cin >> m >> d;
        int days=0;
        for(int i=0;i<m;i++)
            days+=Month[i];
        int w=(days+d+5)%7;
        cout<<Day[w]<<endl;
    }
    return 0;
}