24h購物| | PChome| 登入
2012-03-24 14:57:45| 人氣6,763| 回應0 | 上一篇 | 下一篇

[UVA] 12019 - Doom's Day Algorithm

推薦 0 收藏 0 轉貼0 訂閱站台

A - Doom's Day Algorithm 

Background

No. Doom's day algorithm is not a method to compute which day the world will end. It is an algorithm created by the mathematician John Horton Conway, to calculate which day of the week (Monday, Tuesday, etc.) corresponds to a certain date.

This algorithm is based in the idea of the doomsday, a certain day of the week which always occurs in the same dates. For example, 4/4 (the 4th of April), 6/6 (the 6th of June), 8/8 (the 8th of August), 10/10 (the 10th of October) and 12/12 (the 12th of December) are dates which always occur in doomsday. All years have their own doomsday.

In year 2011, doomsday is Monday. So all of 4/4, 6/6, 8/8, 10/10 and 12/12 are Mondays. Using that information, you can easily compute any other date. For example, the 13th of December 2011 will be Tuesday, the 14th of December 2011 will be Wednesday, etc.

The Problem

Other days which occur on doomsday are 5/9, 9/5, 7/11 and 11/7. Also, in leap years, we have the following doomsdays: 1/11 (the 11th of January) and 2/22 (the 22nd of Febrary), and in non-leap years 1/10 and 2/21.

Given a date of year 2011, you have to compute which day of the week it occurs.

Input

The input can contain different test cases. The first line of the input indicates the number of test cases.

For each test case, there is a line with two numbers: M D. M represents the month (from 1 to 12) and D represents the day (from 1 to 31). The date will always be valid.

Output

For each test case, you have to output the day of the week where that date occurs in 2011. The days of the week will be: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday.

Sample Input

8
1 6
2 28
4 5
5 26
8 1
11 1
12 25
12 31

Sample Output

Thursday
Monday
Tuesday
Thursday
Monday
Tuesday
Sunday
Saturday


#include <stdio.h>
int main() {
int Month[13][32], i, j;
int day = 6, Day[13] = {0, 31, 28, 31, 30, 31, 30,
31, 31, 30, 31, 30, 31};
for(i = 12; i >= 1; i--) {
for(j = Day[i]; j >= 1; j--) {
Month[i][j] = day;
day--;
if(day < 1) day = 7;
}
}
char s[8][10] = {"", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
int T;
scanf("%d", &T);
while(T--) {
scanf("%d %d", &i, &j);
printf("%s\n", s[Month[i][j]]);
}
return 0;
}

台長: Morris
人氣(6,763) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][JAVA] 10579 - Fibonacci Numbers
此分類上一篇:[UVA] 256 - Quirksome Squares

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文