此题关键在于 1 1 1 是星期几 网上搜到的是 星期六
但是由此题推出是 星期一 所以要注意
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
int day[][] = {{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
,{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }};
String weekdays[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int y = sc.nextInt();
int m = sc.nextInt();
int d = sc.nextInt();
if (y <= 0 || y >= 10000 || m <= 0 || m >= 13 || d <= 0 || d >= 32) {
System.out.println("illegal");
continue;
}
if (isLeapYear(y)&&day[1][m]<d) {
System.out.println("illegal");
continue;
}
if (!isLeapYear(y)&&day[0][m]<d) {
System.out.println("illegal");
continue;
}
int ans = 0;
for (int i = 1; i < y; i++) {
if (isLeapYear(i)) {
ans += 366;
}else{
ans += 365;
}
}
for (int i = 1; i < m; i++) {
if (isLeapYear(y)) {
ans += day[1][i];
}else{
ans += day[0][i];
}
}
ans += d;
ans = ans % 7;
System.out.println(weekdays[ans]);
}
sc.close();
}
public static boolean isLeapYear(int year) {
if (year % 400 == 0 || year % 100 != 0 && year % 4 == 0) {
return true;
}
return false;
}
}