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
解法: 建表求解
import java.util.Scanner;
public class UVA12019 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int count = sc.nextInt();
for (int i = 0; i < count; i++) {
int month = sc.nextInt();
int day = sc.nextInt();
int box_month[] = new int[] { 30, 28, 31, 30, 31, 30, 31, 31, 30,
31, 30, 31 };
String box_day[] = new String[] { "Saturday", "Sunday", "Monday",
"Tuesday", "Wednesday", "Thursday", "Friday" };
if (month == 1) {
System.out.println(box_day[(day - 1) % 7]);
}
else {
for (int j = 0; j < (month - 1); j++) {
day += box_month[j];
}
System.out.println(box_day[day % 7]);
}
}
sc.close();
}
}