Advertisement
Spocoman

08. On Time for the Exam

Sep 5th, 2023
670
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. Решение с тернарен оператор:
  2.  
  3. #include <iostream>
  4. #include <iomanip>
  5. #include <string>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10.     int examHour, examMinutes, studentHour, studentMinutes;
  11.     cin >> examHour >> examMinutes >> studentHour >> studentMinutes;
  12.  
  13.     int totalExamMinutes = examHour * 60 + examMinutes;
  14.     int totalStudentMinutes = studentHour * 60 + studentMinutes;
  15.     int diff = totalExamMinutes - totalStudentMinutes;
  16.    
  17.     cout << (diff < 0 ? "Late" : diff > 30 ? "Early" : "On time") << endl;
  18.    
  19.     if (diff != 0) {
  20.         if (abs(diff) < 60) {
  21.             cout << abs(diff) << " minutes " << (diff > 0 ? "before" : "after") << " the start" << endl;
  22.         }
  23.         else {
  24.             cout << (abs(diff) / 60) << ':' << setw(2) << setfill('0') << abs(diff) % 60 << " hours " << (diff > 0 ? "before" : "after") << " the start" << endl;
  25.         }
  26.     }
  27.  
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement