zoj3876 May Day Holiday(判断闰年)

来源:互联网 发布:实用电子产品知乎 编辑:程序博客网 时间:2024/05/18 03:45

此题要推,已知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;}


0 0
原创粉丝点击