Question Link
Returns the number of days in two years.
Just set the template directly.
Calculate the number of days from two years to 0 years to 0 months, respectively, and subtract the absolute value.
Write template
/*************************************** * *********************************> File Name: test. cpp> Author: yangshuo> Mail: 1115332213@qq.com> Created Time: on Wednesday 19, May 22, 2013 ******************************** **************************************** /# include <iostream> # include <stdio. h> # include <cmath> # include <algorithm> # include <string. h> using namespace std; const int days = 365; const int s [] = {, 31, 30, 31}; bool Isleap (int y) {if (y % 400 = 0 | y % 100 & y % 4 = 0) return 1; return 0;} int leap (int y) {if (! Y) return 0; return y/4-y/100 + y/400;} int calc (int day, int mon, int year) {int res = (year-1) * days + leap (year-1); for (int I = 1; I <mon; I ++) res + = s [I]; if (Isleap (year) & mon> 2) res ++; res + = day; return res;} int count_day (int da, int ma, int ya, int db, int mb, int yb) {int resa = calc (da, ma, ya); int resb = calc (db, mb, yb); return abs (resa-resb);} int main () {int ya, ma, da, yb, mb, db; while (scanf ("% d: % d", & ya, & ma, & da )! = EOF) {scanf ("% d: % d", & yb, & mb, & db); printf ("% d \ n", count_day (da, ma, ya, db, mb, yb);} return 0 ;}