#include <iostream> #include <cstdio> using namespace std; int days[][2]={ 0,0, 31,31, 28,29, 31,31, 30,30, 31,31, 30,30, 31,31, 31,31, 30,30, 31,31, 30,30, 31,31 }; int isRun(int year){ if(year%4 ==0 && year%100!=0 || year%400 ==0) return 1; else return 0; } struct Date{ int year; int month; int day; Date(int year,int month,int day) { this->year=year; this->month=month; this->day=day; } void nextDay() { day++; if(day>days[month][isRun(year)]) { day=1; month++; if(month>12) { month=1; year++; } } } bool equalDate(const Date &b){ return (year==b.year && month==b.month && day==b.day) ; } bool operator==(const Date &b)const{ return (year==b.year && month==b.month && day==b.day) ; } bool operator<(const Date &b) const{ if(year!=b.year) return year<b.year; if(month!=b.month) return month<b.month; return day<b.day; } }; void swap(Date &a,Date &b) { Date tmp=a; a=b; b=tmp; } int main() { int y1,m1,d1; int y2,m2,d2; cout<<"请输入日期:"<<endl; while (scanf("%4d%2d%2d",&y1,&m1,&d1)==3 && scanf("%4d%2d%2d",&y2,&m2,&d2)==3 ) { Date a(y1,m1,d1); Date b(y2,m2,d2); if(b<a) swap(a,b); int count=0; while (!(a==b)) { count++; a.nextDay(); } printf("%04d年%02d月%02d日与%04d年%02d月%02d日相差%d天\n",y1,m1,d1,y2,m2,d2,count); cout<<"请输入日期:"<<endl; } return 0; }