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

【蓝桥杯竞赛】 日历问题

时间:2015-05-02 20:41:58      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:

技术分享技术分享

 

#include<stdio.h>
//2001 1 1 Saturday
char week[7][10] = {"Saturday", "Sunday", "Monday", "Tuesday", "Wednesday","Thursday","Friday"};
int year[2] ={365, 366};
int month[2][12] = {{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}};

int type(int year)
{
    if(year%4 != 0 || (year%100 == 0 && year%400 !=0 ))
        return 0;
    else
        return 1;
}
int main()
{
    int days, dayofweek;
    int i, j;
    while(scanf("%d", &days) && days != -1)
    {
        dayofweek = days%7;
        for(i = 2000; days >year[type(i)]; i++)
            days -= year[type(i)];
        for(j = 0; days > month[type(i)][j]; j++)
            days -= month[type(i)][j];
        printf("%d-%02d-%02d %s\n", i , j+1, days+1, week[dayofweek]);
    }
    return 0;
}

 

【蓝桥杯竞赛】 日历问题

标签:

原文地址:http://www.cnblogs.com/superkrissV/p/4472464.html

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