#include <iostream>
using namespace std;
class Tm{
public:
Tm(){h=0;m=0;s=0;}
Tm(int xh,int xm,int xs){h=xh,m=xm,s=xs;}
Tm operator+(Tm &t)
{
Tm res;
if((this->h+t.h)<24 && (this->m+t.m)<60 && (this->s+t.s)<60)
{ res.h=this->h+t.h;
res.m=this->m+t.m;
res.s=this->s+t.s;
return res;}
else if((this->h+t.h)<24 && (this->m+t.m)<60 && (this->s+t.s)>60)
{
res.s=(this->s+t.s) % 60;
res.m=(this->m+t.m)+1;
if((this->m+t.m)+1==60)
{
res.m=0;
res.h=(this->h+t.h)+1;
}
else
{
res.h=(this->h+t.h);
}
return res;
}
else if((this->h+t.h)<24 && (this->m+t.m)>60 && (this->s+t.s)<60)
{
res.m=(this->m+t.m) % 60;
res.h=(this->h+t.h)+1;
res.s=(this->s+t.s);
return res;
}
}
Tm operator-(Tm &t)
{
Tm res;
res.h=this->h-t.h;
res.m=this->m-t.m;
res.s=this->s-t.s;
return res;
}
int &operator[](int i)
{
if(i==0)
{
return s;
}
if(i==1)
{
return m;
}
if(i==2)
{
return h;
}
}
void show(){cout<<"h="<<h<<" m="<<m<<" s="<<s<<endl;}
private:
int h;
int m;
int s;
};
int main(int argc, const char *argv[])
{
Tm t1;
Tm t2(3,2,14);
Tm t3(4,59,20);
t1=t2+t3;
t1.show();
t1=t3-t2;
t1.show();
int sec=t3[1];
cout<<sec<<endl;
t3[1]=55;
t3.show();
return 0;
}