HDU2133 What day is it

2133

What day is it

Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5952 Accepted Submission(s): 1811

Problem Description T

oday 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

#include <cstdio>
const char *ans[7] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
int isLeap(int y)
{
    return !(y % 4) && (y % 100) || !(y % 400);
}
int main()
{
    int y, m, d, c, w;
    while (~scanf("%d%d%d", &y, &m, &d))
    {
        if (d <= 0 || m <= 0 || d >= 10000 || m > 12 || d > 31)
        {
            printf("illegal\n");
            continue;
        }
        if (!isLeap(y) && m == 2 && d > 28)
        {
            printf("illegal\n");
            continue;
        }
        if (isLeap(y) && m == 2 && d > 29)
        {
            printf("illegal\n");
            continue;
        }
        if ((m == 4 || m == 6 || m == 9 || m == 11) && d > 30)
        {
            printf("illegal\n");
            continue;
        }
        if (m<=2)//蔡勒公式中月份1 2要看做上一年的13 14月份
        {
            m += 12;
            y--;
        }
        c = y / 100;//century世纪,即年份的前两位
        y %= 100;//年份的后两位
        w = c/4 - c*2 + y + y/4 + 13 * (m + 1) / 5 + d - 1;//蔡勒公式
        w = (w % 7 + 7) % 7;//使结果为正数
        printf("%s\n", ans[w]);
    }
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值