#include<iostream>
using namespace std;
//你提交的代码在这里
int day(int a,int b,int c)
{
int d[12]= {31,28,31,30,31,30,31,31,30,31,30,31};
if(a%4==0&&a%100!=0||a%400==0)
d[1]=29;
for(int i=0; i<b-1; i++)
{
c+=d[i];
}
return c;
}
int day(int b,int a)
{
int d[12]= {31,28,31,30,31,30,31,31,30,31,30,31};
if(a%4==0&&a%100!=0||a%400==0)
d[1]=29;
return d[b-1];
}
class Date {
public:
Date():h(2023),s(20),m(5) {}
//Rectangle (double a,double b):w(a),h(b){}
Date(int a,int b,int c):h(a),m(b),s(c){}
void Set(int a,int b,int c){h=a,m=b,s=c;}
Date(const Date &a):s(a.s),h(a.h),m(a.m) {}
int operator -(const Date&a)
{
if(h==a.h)
return day(h,m,s)-day(a.h,a.m,a.s);
if(h<a.h)
{
int b=0;
for(int i=h+1; i<a.h; i++)
b+=day(i,12,31);
b+=day(a.h,a.m,a.s);
return b-day(h,m,s);
}
if(h>a.h)
{
int b=0;
for(int i=a.h+1; i<h; i++)
b+=day(i,12,31);
b+=day(h,m,s);
return b-day(a.h,a.m,a.s);
}
}
Date operator+(int n)
{
Date p(h,m,s);
int count=0;
for(p.h;;)
{
for(p.m; p.m<=12; p.m++)
{
for(p.s; p.s<=day(p.m,p.h); p.s++)
{
if(count==n)
return Date(p.h,p.m,p.s);
count++;
}
p.s=1;
}
p.m=1;
p.h++;
}
}
Date operator-(int n)
{
Date p(h,m,s);
int count=0;
if(p.s-1>=n)
return Date(p.h,p.m,p.s-n);
else
{ // count=1;
p.m--;
if(p.m==0)
{
p.m=12;
p.h--;
}
count+=p.s;
for(p.h;;)
{
for(p.m; p.m>=1; p.m--)
{
p.s=day(p.m,p.h);
for(p.s=day(p.m,p.h); p.s>=1; p.s--)
{
if(count==n)
return Date(p.h,p.m,p.s);
count++;
}
}
p.m=12;
p.h--;
}
}
}
friend ostream& operator<<(ostream &a,const Date &b)//const Circle &b)
{
a<<b.h<<"/"<<b.m<<"/"<<b.s;
return a;
}
friend istream& operator >>(istream&a,Date&b)
{
a>>b.h>>b.m>>b.s;
return a;
}
bool operator >(const Date &a)
{
if(h>a.h)
return true;
else if(h==a.h)
{
if(day(h,m,s)>day(a.h,a.m,a.s))
return true;
else
return false;
}
else return false;
}
private:
int h,m,s;
};
int main()
{
Date d1;
cout<<"Show object d1:"<<d1<<endl;
int year,month,day;
cin>>year>>month>>day;
Date d2(year,month,day);
cout<<"Show object d2:"<<d2<<endl;
cin>>year>>month>>day;
d1.Set(year,month,day);
cout<<"Reset and Show object d1:"<<d1<<endl;
int n;
n=d2-d1;
cout<<d2<<" - "<<d1<<" = "<<n<<endl;
cin>>n;
cout<<d1<<" + "<<n<<" = ";
d2=d1+n;
cout<<d2<<endl;
cout<<d1<<" - "<<n<<" = ";
d1=d1-n;
cout<<d1<<endl;
return 0;
}
/*
2023 1 5
2020 7 8
800
*/