文章标题

1199: 英雄无敌3(2)

Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 306 Solved: 53
[Submit][Status][Web Board]
Description

英雄无敌3中的兽人觉得人类的星期制度很好,要模仿这个制度,但他们大多都很愚蠢,他们搞不明白人类的星期制度。虽然他们出了很多题目(给出日期,输出星期几),但不知道答案,作为兽人的人类朋友,你可以帮助他们吗?(为了表示方便,0代表星期天,1代表星期一,2代表星期二,3代表星期三,4代表星期四,5代表星期五,6代表星期六)

Input

第一行输入一个数t,代表题目数。

每个题目有3个正整数分别为y(0 < y < = 2013), m(0 = < m<=20), d(0<=d<=40)分别代表年,月,日。

Output

对于每组案例,输出一个整数,代表星期几(当然由于兽人很愚蠢,他们给出的日期有可能是不存在的,对于这种情况,请输出-1)

Sample Input

1
2013 4 25
Sample Output

4
HINT

Source

蔡勒公式

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>

int main()
{
    int t, year, mouth, day;
    scanf("%d", &t);
    while (t--)
    {
        int m[13] = { 0,31,29,31,30,31,30,31,31,30,31,30,31 };
        scanf("%d%d%d", &year, &mouth, &day);
        if (mouth == 0 || mouth>12 || day == 0 || day>31)
        {
            printf("-1\n");
            continue;
        }
        if (!((year % 4 == 0 && year % 100 != 0) || year % 400 == 0))
        {
            m[2] = 28;
        }
        if (day>m[mouth])
        {
            printf("-1\n");
            continue;
        }
        if (mouth<3)
        {
            year--;
            mouth += 12;
        }
        int c = year / 100;
        int y = year % 100;
        printf("%d\n", ((c / 4 - 2 * c + y + y / 4 + 13 * (mouth + 1) / 5 + day - 1) % 7 + 7) % 7);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值