#include <iostream>
using namespace std;
int main() {
int h, m, s, time;
cin >> h >> m >> s >> time;
int hour, minute, second;
second = time % 60;
time -= second;
time = time/60;
minute = time % 60 ;
hour = time / 60;
if ( s + second > 60 ) {
s = (s+second) % 60;
if ( m + minute + 1 > 60 ) {
m = (m+minute+1) % 60;
if ( h + hour + 1 >= 24 ) {
h = (h+hour+1) % 24;
} else {
h+=hour+1;
}
} else if( m + minute + 1 == 60 ) {
m = 0;
m = m+minute;
if ( h + hour >= 24 ) {
h = (h+hour) % 24;
h += hour;
} else if ( s+second == 60 ) {
h +=hour+1;
m += minute;
h = h + hour;
s = s+second;
if ( m + minute > 60 ) {
m = (m+minute) % 60;
} else if( m + minute == 60 ) {
h += hour+1;
cout << h << ":" << m << ":" << s;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <iostream>
using namespace std;
int main() {
int h, m, s, time;
cin >> h >> m >> s >> time;
int hour, minute, second;
second = time % 60;
time -= second;
time = time/60;
minute = time % 60 ;
hour = time / 60;
if ( s + second > 60 ) {
s = (s+second) % 60;
if ( m + minute + 1 > 60 ) {
m = (m+minute+1) % 60;
if ( h + hour + 1 >= 24 ) {
h = (h+hour+1) % 24;
} else {
h+=hour+1;
}
} else if( m + minute + 1 == 60 ) {
m = 0;
if ( h + hour + 1 >= 24 ) {
h = (h+hour+1) % 24;
} else {
h+=hour+1;
}
} else {
m = m+minute;
if ( h + hour >= 24 ) {
h = (h+hour) % 24;
} else {
h += hour;
}
}
} else if ( s+second == 60 ) {
s = (s+second) % 60;
if ( m + minute + 1 > 60 ) {
m = (m+minute+1) % 60;
if ( h + hour + 1 >= 24 ) {
h = (h+hour+1) % 24;
} else {
h+=hour+1;
}
} else if( m + minute + 1 == 60 ) {
m = 0;
if ( h + hour + 1 >= 24 ) {
h = (h+hour+1) % 24;
} else {
h +=hour+1;
}
} else {
m += minute;
if ( h + hour >= 24 ) {
h = (h+hour) % 24;
} else {
h = h + hour;
}
}
} else {
s = s+second;
if ( m + minute > 60 ) {
m = (m+minute) % 60;
if ( h + hour + 1 >= 24 ) {
h = (h+hour+1) % 24;
} else {
h+=hour+1;
}
} else if( m + minute == 60 ) {
m = 0;
if ( h + hour + 1 >= 24 ) {
h = (h+hour+1) % 24;
} else {
h += hour+1;
}
} else {
m += minute;
if ( h + hour >= 24 ) {
h = (h+hour) % 24;
} else {
h += hour;
}
}
}
cout << h << ":" << m << ":" << s;
}