import java.util.Scanner; /*:w = (d + [2.6m - 0.2] + 5(y % 4) + 3y + 5(c % 4)) % 7 d = 日期 m = 月数 - 2(1月为11月,2月为12月) y = 年数后2位(1、2月份y - 1) c = 世纪数 * */ public class Main { public static void main(String arg[]){ //月 String[] month = {"January", "February", "March", "April", "May", "June" ,"July", "August","September", "October", "November", "December"}; String[] week = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; Scanner sc = new Scanner(System.in); while(sc.hasNext()){ String temp = sc.nextLine(); String[] str = temp.split(" "); Integer day = Integer.parseInt(str[0]); //月份计算 Integer mon=1; for(String i:month){ if(i.equals(str[1])) break; mon++; } Integer m =0; if(mon==1 || mon==2) m = mon+10; else m = mon-2; //年份计算 Integer cen = Integer.parseInt(str[2].substring(0, 2)); Integer year = Integer.parseInt(str[2].substring(2, 4)); Integer y=0; if(mon==1 || mon==2) y=year-1; else y=year; if(y==-1) { y=99; cen--; } Integer w = (day+(int)(Math.floor(2.6*(float)m-0.2))+5*(y%4)+3*y+5*(cen%4))%7; System.out.println(week[w]); } } }
题目1043:Day of Week
题目1043:Day of Week
参考代码: