Description
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).
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.
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
其实我不太懂为什么不用考虑题目给的条件,难道0年1月1日是星期日吗?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
#include<stdio.h>
#include<iostream>
using namespace std;
string a[7]= {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
int s[13]= {0,31,28,31,30,31,30,31,31,30,31,30,31};
int IsLeap(int y)
{
if((y%4==0&&y%100!=0)||y%400==0)
return 1;
else
return 0;
}
int judge(int y,int m,int d)
{
if(y>0&&y<10000&&m>0&&m<13&&d>0)
{
if(m==2)
return d<=s[2]+IsLeap(y);
else
return d<=s[m];
}
else
return 0;
}
int day(int y,int m,int d)
{
int r=0;
for(int i=1; i<y; i++)
r+=365+IsLeap(i);
s[2]+=IsLeap(y);
for(int i=1; i<m; i++)
r+=s[i];
s[2]=28;
return r+d;
}
int main()
{
int y=0,m=0,d=0;
while(scanf("%d%d%d",&y,&m,&d)!=EOF)
{
if(judge(y,m,d)==0)
cout<<"illegal"<<endl;
else
{
cout<<a[day(y,m,d)%7]<<endl;
}
}
return 0;
}