屬於比較討厭的CPE 一星題,如果你沒有想到投機的寫法的話XD
大於 0 ==> %7 去對照星期表,得解
小於 0 ==> %7 + 7 去對照星期表,得解
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#define Mo "Monday"
#define Tu "Tuesday"
#define We "Wednesday"
#define Th "Thursday"
#define Fr "Friday"
#define Sa "Saturday"
#define Su "Sunday"
/*
解題: Doms Day Algorithm
解題者:神里綾華的狗
這次這樣亂搞(一堆定義)主要是防抄用
*/
using namespace std;
/*
note :(all monday)
4/4 ==>擬用
6/6
8/8
10/10
12/12
*/
// 建置表 ==> 每月的個星期一
const vector<int> Ever_Mon_Monday = {-1, 10, 21, 7, 4, 9, 6, 11, 8, 5, 10, 7, 12};
// 建置表 ==> 星期
const vector<string> day = {Mo, Tu, We, Th, Fr, Sa, Su};
int main(int argc, char const *argv[])
{
int t;
cin >> t;
while (t--)
{
int m, d;
cin >> m >> d;
int key = d - Ever_Mon_Monday[m];
key = key % 7;
if (key >= 0)
{
cout << day[key] << endl;
}
else
{
key = 7 + key;
cout << day[key] << endl;
}
}
return 0;
}