码迷,mamicode.com
首页 > 其他好文 > 详细

<swustoj>?id=78 计算生日是星期几

时间:2016-07-30 12:06:21      阅读:268      评论:0      收藏:0      [点我收藏+]

标签:

链接http://acm.swust.edu.cn/problem/0078/

#include <stdio.h>
bool LeapYear(int year)
{
    return((year%400==0)||(year%100!=0&&year%4==0));
}
int main()
{
    int i;
    int year,month,day;
    int sum;
    int monthday[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    while(~scanf("%d %d %d",&year,&month,&day))
    {
        sum=day;
        for(i=1;i<year;i++)
        {
            if(LeapYear(i))
            {
                sum+=366;
            }
            else
            {
                sum+=365;
            }
        }
        if(LeapYear(year))
        {
            monthday[2]=29;
        }
        for(i=1;i<month;i++)
        {
            sum+=monthday[i];
        }
        monthday[2]=28;
        //printf("%d\n",sum);
        switch(sum%7)
        {
        case 1:printf("Monday\n");break;
        case 2:printf("Tuesday\n");break;
        case 3:printf("Wednesday\n");break;
        case 4:printf("Thursday\n");break;
        case 5:printf("Friday\n");break;
        case 6:printf("Saturday\n");break;
        case 0:printf("Sunday\n");break;
        }
    }
    return 0;
}

 

<swustoj>?id=78 计算生日是星期几

标签:

原文地址:http://www.cnblogs.com/niconiconi/p/5720520.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!