法一:硬算 暴力


#include <bits/stdc++.h>
using namespace std;
int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
string mmon[13]={"","January","Febrary","March","April","May","June","July","August","September","October","November","December"};
string dd[7]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
int leap(int year){
	if((year%4==0 && year%100!=0) || year%400==0) return 1;
	return 0;
}

int main(){
	int dday,year,mm,sum=0;
	string mon;
	//0年1月1日星期一 
	while(cin>>dday>>mon>>year){
		sum=0;
		for(int i=1;i<=12;i++){
		if(mon==mmon[i]){
			mm=i;
			break;
		}
	}
	for(int yy=1;yy<year;yy++){
		if(leap(yy)) sum+=366;
		else sum+=365;
	}
	if(leap(year)) day[2]=29;
		else day[2]=28;
	for(int i=1;i<mm;i++){
		sum+=day[i];
	}	
	sum+=dday;
	cout<<dd[(sum)%7]<<endl;
}
	return 0;
}

法二:基姆拉尔森计算公式

#include <bits/stdc++.h>
using namespace std;
int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
string mmon[13]={"","January","Febrary","March","April","May","June","July","August","September","October","November","December"};
string dd[7]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
int leap(int year){
	if((year%4==0 && year%100!=0) || year%400==0) return 1;
	return 0;
}

int main(){
	int dday,year,mm,sum=0;
	string mon;
	//0年1月1日星期一 
	while(cin>>dday>>mon>>year){
		sum=0;
		for(int i=1;i<=12;i++){
		if(mon==mmon[i]){
			mm=i;
			break;
		}
	}
	if(mm==1 || mm==2) {
		mm+=12;
		year-=1;
	}
	sum=(dday+2*mm+3*(mm+1)/5+year+year/4-year/100+year/400+1)%7;
	cout<<dd[sum]<<endl;
}
	return 0;
}