输入描述输入一个正整数s
输出描述按样例输出
提示你需要提交除了main函数之外的其他代码。
样例输入
333
样例输出
13:24:47
21:16:6
-28279
#include<iostream>
using namespace std;
#include<iostream>
using namespace std;
#define pi 3.14159265
#include<iostream>
using namespace std;
class Time
{
private:
int hour, minute, second;
public:
Time() { hour = 0; minute = 0; second = 0; }
Time(int hour, int minute, int second)
{
this->hour = hour;
this->minute = minute;
this->second = second;
}
friend ostream& operator<<(ostream& out, Time& t)
{
out << t.hour << ":" << t.minute << ":" << t.second << endl;
return out;
}
Time& operator+(const int s)
{
second += s;
if (second >= 60)
{
int p = second / 60;
minute += p;
second = second % 60;
}
if (minute >= 60)
{
int g = minute / 60;
hour += g;
minute = minute % 60;
}
if (hour >= 24)
{
hour = hour % 24;
}
return *this;
}
Time& operator-(const int s)
{
int g = hour * 3600 + minute * 60 + second - s;
if (g >= 0)
{
hour = g /3600;
minute = (g % 3600) / 60;
second= (g % 3600) % 60;
}
if (g < 0)
{
g=-g;
hour = 23 - (g / 3600);
minute = 59 - ((g % 3600) / 60);
second = 60 - ((g % 3600) % 60);
}
return *this;
}
friend int operator-(const Time& t1, const Time& t2)
{
int g1 = t1.hour * 3600 + t1.minute * 60 + t1.second;
int g2 = t2.hour * 3600 + t2.minute * 60+ t2.second;
return g1 - g2;
}
};