标签:style blog color io os ar for strong sp
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 }
很好的倒计日计算!代码来源于网络,特发此与大家分享,感谢原作者!
标签:style blog color io os ar for strong sp
原文地址:http://www.cnblogs.com/zhangfan2014/p/4049750.html