PKU2080

http://acm.pku.edu.cn/JudgeOnline/problem?id=2080
 1
 #include <stdio.h>
 2 
 3 int main(void)
 4 {
 5     int m1[12]={31,28,31,30,31,30,31,31,30,31,30,31};
 6     int m2[12]={31,29,31,30,31,30,31,31,30,31,30,31};
 7     char week[7][10]={"Saturday","Sunday","Monday",
 8            "Tuesday","Wednesday","Thursday","Friday"};
 9     int days, weekday;
10     scanf("%d",&days);
11 
12     while (days != -1) {
13         days++;
14         weekday = (days - 1% 7;
15 
16         int daysinyear = 0;
17         int ithyear = 0;
18 
19         while (days > 0) {   /* 确定年 */
20             if (ithyear % 100 == 0 && ithyear % 400 != 0) daysinyear = 365;
21             else if (ithyear % 4 == 0) daysinyear = 366;
22             else daysinyear = 365;
23             days -= daysinyear;
24             ithyear ++;
25         }
26 
27         ithyear --;
28         days += daysinyear;
29         int ithmonth = 0;
30         while (days > 0) {    /* 确定月 */
31             if (daysinyear == 365) days -= m1[ithmonth];
32             else days -= m2[ithmonth];
33             ithmonth ++;
34         }
35 
36         if (daysinyear == 365) days += m1[ithmonth-1];      /* 确定天 */
37         else days += m2[ithmonth-1];
38 
39         printf ("%d-%02d-%02d %s\n",
40             2000 + ithyear,ithmonth,days,week[weekday]);
41         scanf("%d",&days);
42     } /*  while */
43 /*  main */
44 
45 
46 

posted on 2009-02-11 20:44 啄来魔去 阅读(129) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

导航

统计

常用链接

留言簿

随笔档案

文章档案

搜索

最新评论

阅读排行榜

评论排行榜