zoj3876 May Day Holiday(判断闰年)

此题要推,已知2015年5月1号是星期五,推出1928年。注意千万不要手算,用程序推(反正我是这样)。闰年52周零2天,平年52周零1天,所以推的时候闰年减2,平年减一就好,最后推出1928年5月1号是星期二。然后按照同样的方式递归打表就好了。


ps:我还WA了几次居然是判断闰年函数写错了,后面应该再判断一次不等于。深深地体现出我基础的薄弱啊。。。

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <queue>
#include <string.h>
using namespace std;

const int N = 20000;
const int INF = 1000000;

int is_leap(int x)
{
    if((x % 100 == 0 && x % 400 == 0) || (x % 100 != 0 && x % 4 == 0))
        return 1;
    else return 0;
}

int main()
{
   // freopen("in.txt", "r", stdin);
    int T, y, a[N];
    int num = 2;
    memset(a, 0, sizeof(a));
    for(int i = 1928; i <= 10000; i ++)
    {
        a[i] = num;
//           printf("%d %d\n", i, num);
        if(is_leap(i + 1))
        {
            num += 2;
        }
        else num += 1;
        if(num > 7) num -= 7;
    }
    scanf("%d", &T);
    while(T --)
    {
        scanf("%d", &y);
        if(a[y] == 1) printf("9\n");
        else if(a[y] == 2 || a[y] == 7) printf("6\n");
        else if(a[y] == 3 || a[y] == 4 || a[y] == 5 || a[y] == 6) printf("5\n");
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值