zoj 2420

题意:给出天数,让你输出该天数后的日期

2000使润年。。。。

#include<stdio.h>
int Is_leap(int i)
{
    if(i%400==0 || (i%4==0 && i%100!=0)) return 1;
    return 0;
}
int main()
{
    int n;
    int i,j;
    char a[8][10]={"Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday"};
    int b[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    int c[]={0,31,29,31,30,31,30,31,31,30,31,30,31};
    while(scanf("%d",&n))
    {
        int t=n;
        int sum=0;
        if(n==-1) break;
        for (i=2000;;i++)
        {
                if(Is_leap(i))
                {
                    if(n-sum-366>=0) sum+=366;
                    else break;
                }
                else
                {
                    if(n-sum-365>=0) sum+=365;
                    else break;
                }
        }
        n=n-sum+1;
        for (j=1;j<=12;j++)
        {
            if(j!=2)
            {
                if(n-b[j]>0) n-=b[j];
                else break;

            }
            else
            {
                if(Is_leap(i))
                {
                    if(n-c[j]>0) n-=c[j];
                    else break;
                }
                else
                {
                    if(n-b[j]>0) n-=b[j];
                    else break;
                }
            }
        }
        printf("%d-%02d-%02d %s\n",i,j,n,a[t%7]);

    }
    return 0;
}
posted @ 2012-06-01 21:01  calmound  阅读(239)  评论(0编辑  收藏  举报