HDU - 2133 What day is it (蔡勒公式+模拟)

Today is Saturday, 17th Nov,2007. Now, if i tell you a date, can you tell me what day it is ?

Input

There are multiply cases.
One line is one case.
There are three integers, year(0<year<10000), month(0<=month<13), day(0<=day<32).

Output

Output one line.
if the date is illegal, you should output "illegal". Or, you should output what day it is.

Sample Input

2007 11 17

Sample Output

Saturday

代码:

#include<iostream>

using namespace std;

bool m[] = {false,true,false,true,false,true,false,true,true,false,true,false,true};
char b[7][10]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};

int main()
{
	int year,month,day;
	while(cin>>year>>month>>day)
	{
		if((year == 0 || month == 0 || day == 0) || (month == 2 && day>29) || (!m[month] && day == 31))
		{
		    printf("illegal\n");
		    continue;
		}
		if(!(year%4 == 0 && year%100 != 0 ||year%400 == 0)&&month == 2 && day == 29)
		{
			printf("illegal\n");
		    continue;
		} 
		if(month<3)
		{
			year-=1;
			month+=12;
		}
		int c= int(year/100),y = year-100*c;
		int w= int(c/4)-2*c+y+int(y/4) + (26*(month+1)/10)+day-1;
		w=(w%7+7)%7;
		cout<<b[w]<<endl;
	}
	return 0;
}

 

posted @ 2018-08-12 13:13  Assassin_poi君  阅读(207)  评论(0编辑  收藏  举报