Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- int hours, minutes;
- cin >> hours >> minutes;
- string dayPart;
- cin >> dayPart;
- int hoursAdded, minutesAdded;
- cin >> hoursAdded >> minutesAdded;
- int result = (hours + hoursAdded) * 60 + minutes + minutesAdded;
- int totalHours = result / 60 % 24;
- int totalMinutes = result % 60;
- dayPart = totalHours >= 12 ? (dayPart == "AM" ? "PM" : "AM") : dayPart;
- totalHours -= totalHours > 12 ? 12 : 0;
- printf("%.2d:%.2d:%s\n", totalHours, totalMinutes, dayPart.c_str());
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement