#include<iostream>
using namespace std;
int mod(int a, int b) {
return ((a % b) + b) % b;
}
int div_floor(int a, int b) {
return a / b + ((a < 0 && a / b == (a + 1) / b) ? -1 : 0);
}
class Time {
public:
int H, M, S;
Time(int h, int m, int s) {
//todo : Implement constructor
this->H = mod(h, 24);
this->M = mod(m, 60);
this->S = mod(s, 60);
}
Time operator+(const Time& input) {
//todo : Implement addition
int s = input.S + this->S;
int m = input.M + this->M + s / 60;
int h = input.H + this->H + m / 60;
return Time(h, m, s);
}
Time operator-(const Time& input) {
//todo : Implement subtraction
int s = this->S - input.S + 60;
int m = this->M - input.M + s / 60 + 59;
int h = this->H - input.H + m / 60 + 23;
return Time(h, m, s);
}
Time operator*(const int& input) {
//todo : Implement subtraction
int s;
int m;
int h;
if (true) {
s = input * this->S;
m = input * this->M + div_floor(s, 60);
h = input * this->H + div_floor(m, 60);
}
return Time(h, m, s);
}
friend Time operator*(int& input, Time& p) {
return p * input;
}
void print_time() {
cout << H << ":" << M << ":" << S << endl;
}
};
//todo : Implement time multiplication
int main() {
int a, b, c;
int d, e, f;
int num1, num2;
cin >> a >> b >> c;
cin >> d >> e >> f;
cin >> num1 >> num2;
Time t1(a, b, c);
Time t2(d, e, f);
Time sum = t1 + t2;
Time diff = t1 - t2;
Time mul1 = t1 * num1;
Time mul2 = num2 * t2;
sum.print_time();
diff.print_time();
mul1.print_time();
mul2.print_time();
return 0;
}
gpt에 그대로 복사 붙여넣기하면 자세히 설명해줌