#include <iostream> using namespace std; int day[]={ 0,31,28,31,30,31,30,31,31,30,31,30,31 }; int Get_YearMonthDay(int year, int month) { int ret_day = day[month]; (month==2) && (year%4==0 && year%100!=0 ||year%400==0) && (ret_day++); return ret_day; } class Date{ public: Date(int year=0,int month=0,int day=0): _year(year),_month(month),_day(day){ } // >操作符重载 bool operator>(const Date& d) { if(_year > d._year) return true; else if(_year < d._year) return false; else{ if(_month>d._month) return true; else if(_month < d._month) return false; else{ if(_day>d._day) return true; else return false; } } } //日期-天数,返回新的日期 Date operator-(int day) { Date temp(*this); temp._day -= day; while(temp._day<1) { temp._month = temp._month==1? 12 : temp._month-1; if(temp._month ==12) temp._year--; temp._day += Get_YearMonthDay(temp._year,temp._month); } return temp; } int operator-(Date& d)//日期-日期,返回天数差(同一天返回1) { //由于不知道-左右操作数那个日期大,那个日期小,所以又重载了>操作符 Date* max,* min; max = (*this) > d ? this : (&d);//max指针抓大的日期 min = max==this ? (&d) : this;//min抓小 int day = 0; while((*max)-day > (*min)) { day++; } return day+1; } private: int _year; int _month; int _day; }; int main() { int a, b; while (cin >> a >> b) { // 注意 while 处理多个 case int year1=a/10000, year2=b/10000, month1=(a/100)%100, month2=(b/100)%100, day1=a%100, day2=b%100; Date A(year1,month1,day1); Date B(year2,month2,day2); cout<<A-B; } } // 64 位输出请用 printf("%lld")