就是给你两个日期,让你求两个日期之间差多少天。
我先算出两个日期分别是公元多少天,然后相减得到结果。
1.//cf 304B //2013-06-05-18.38 #include <stdio.h> #include <stdlib.h> int y, m, d; int a[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int loop(int y) { if (y%4 == 0 && y%100 != 0 || y%400 == 0) return 1; return 0; } int count() { int sum = 0; for (int i = 1; i < y; i++) { sum += 365; if (loop(i)) sum++; } for (int i = 1; i < m; i++) sum += a[i]; if (loop(y) && m > 2) sum += 1; sum += d; return sum; } int main() { scanf("%d:%d:%d", &y, &m, &d); int ans1 = count(); scanf("%d:%d:%d", &y, &m, &d); int ans2 = count(); printf("%d\n", abs(ans2 - ans1)); return 0; }