今天來解YKL10(UVA12019):Doom's Day Algorithm
有一個關鍵4/4是Monday
4/4 = 94 days
算一下就可以知道1/1是Friday
第一個參數 => month
第二個參數 => days
#include <iostream>
#include <string>
using namespace std;
int main(){
int n,m,d;
int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
string days[] = {"Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday"};
cin >> n;
for(int i = 0;i < n;i++){
cin >> m >> d ;
int result,count=0;
for(int j=1;j < m;j++){
count += month[j];
}
count += d;
result = count % 7;
cout << days[result] << endl;
}
return 0;
}