Advertisement
Spocoman

Exam Schedule

Oct 12th, 2023
1,071
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     int hours, minutes;
  8.     cin >> hours >> minutes;
  9.  
  10.     string dayPart;
  11.     cin >> dayPart;
  12.  
  13.     int hoursAdded, minutesAdded;
  14.     cin >> hoursAdded >> minutesAdded;
  15.  
  16.     int result = (hours + hoursAdded) * 60 + minutes + minutesAdded;
  17.     int totalHours = result / 60 % 24;
  18.     int totalMinutes = result % 60;
  19.  
  20.     dayPart = totalHours >= 12 ? (dayPart == "AM" ? "PM" : "AM") : dayPart;
  21.     totalHours -= totalHours > 12 ? 12 : 0;
  22.  
  23.     printf("%.2d:%.2d:%s\n", totalHours, totalMinutes, dayPart.c_str());
  24.  
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement