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



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

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日是星期日吗?


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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值