首页 > 其他 > 详细

【转载】很好的倒计日计算!赞!

时间:2014-10-25 10:29:34      阅读:252      评论:0      收藏:0      [点我收藏+]
 1 #include <stdio.h>
 2  
 3 unsigned char isleapyear(int y)
 4 {
 5     return (y % 4 == 0 && y % 100 || y % 400 == 0);
 6 }
 7 
 8 int sum(int y, int m, int d)
 9 {
10         int i;
11     int md[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
12     int cnt = y * 365;
13     cnt += (y - 1) / 4 + 1;
14     cnt -= (y - 1) / 100 + 1;
15     cnt += (y - 1) / 400 + 1;
16     for(i = 1; i < m; ++i) cnt += md[i];
17     if(m > 2 && isleapyear(y)) ++cnt;
18     cnt += d;
19     return cnt;
20 }
21 
22 int Count(int y1, int m1, int d1, int y2, int m2, int d2)
23 {
24     return sum(y2, m2, d2) - sum(y1, m1, d1);
25 }
26  
27 int main()
28 {
29     int y1, m1, d1, y2, m2, d2;
30         
31     while(scanf("%d%d%d%d%d%d", &y1, &m1, &d1, &y2, &m2, &d2) == 6)
32         {
33         printf("%d\n", Count(y1, m1, d1, y2, m2, d2));
34     }
35 
36     return 0;
37 }

很好的倒计日计算!代码来源于网络,特发此与大家分享,感谢原作者!



 

【转载】很好的倒计日计算!赞!

原文:http://www.cnblogs.com/zhangfan2014/p/4049750.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!