``````/*
* UVA_602.cpp
*
*  Created on: 2013年10月25日
*/

#include <iostream>
#include <cstdio>

using namespace std;

//星期数组
const char wstr[][20]={
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
};

//月份数组
const char mstr[][20]={
"",
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
};

//判断是否是闰年
bool isLeap(int year , bool old = false){
if(old){//旧的的判断规则
return (year%4 == 0) ? true : false;
}

//新的判断规则
return (year%100 == 0)?(year%400 == 0?true:false):(year%4 == 0?true : false);
}

//求year年有多少天。。这时候需要判断一下他是旧历的年份还是心里的年份。因为2中日期系统的闰年的判断方法不一样
int days_of_year(int year , bool old){
return isLeap(year,old)?366:365;
}

//求year年的month月有多少天..在这里心里和旧历的月份的天数的规定是一样的
int days_of_month(int month,int year , bool leap){
if(month == 2){
return leap?29:28;
}

int d;
switch(month){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
d = 31;
break;
default:
d = 30;
}

return d;
}

//判断year年的month月的day是否使用的是旧历
bool isOld(int year,int month,int day){
if(year < 1752 || (year == 1752 && month < 9) || (year == 1752 && month == 9 && day <=2)){
return true;
}

return false;
}

//判断一个日期是否有效
bool isValid(int year,int month , int day , bool old){
if(year < 1){
return false;
}

if(month < 1 || month > 12){
return false;
}

if(day < 1 || day > days_of_month(month,year,isLeap(year,old))){
return false;
}

if(year == 1752 && month == 9 && day>=3 && day<= 13){
return false;
}

return true;

}

int main(){
int month ,day,year;
while(scanf("%d%d%d",&month,&day,&year)!=EOF,month||day||year){
bool old = isOld(year,month,day);

if(!isValid(year,month,day,old)){
cout<<month<<"/"<<day<<"/"<<year<<" is an invalid date."<<endl;
}else{
int yy,mm;
int sum = 0;
//两个不同的日期系统的转换关键在于天数的计算。。
for(yy = 1 ; yy < year ; ++yy){
sum += days_of_year(yy,old);
}

for(mm = 1 ; mm < month ; ++mm){
sum += days_of_month(mm,year,isLeap(year,old));
}

sum +=day;

int week = sum % 7;
if(old){
week = (week+5)%7;
}

cout<<mstr[month]<<" "<<day<<", "<<year<<" is a "<<wstr[week]<<endl;
}
}

return 0;
}``````