606第九周周三赛 E - What day is it今天星期几

来源:互联网 发布:车辆数据 编辑:程序博客网 时间:2024/06/07 06:39



E - What day is it
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
Submit Status Practice HDU 2133

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). 
 

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


其实我不太懂为什么不用考虑题目给的条件,难道0年1月1日是星期日吗?


1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
#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;}

0 0