Advertisement
TwITe

Untitled

Sep 14th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. struct time {
  2.     int hours;
  3.     int minutes;
  4.     int seconds;
  5.     vector <int> marks;
  6. };
  7.  
  8. bool time_compare(const time& first_time, const time& second_time) {
  9.     if (first_time.hours != second_time.hours) {
  10.         return first_time.hours < second_time.hours;
  11.     }
  12.     else {
  13.         if (first_time.minutes != second_time.minutes) {
  14.             return first_time.minutes < second_time.minutes;
  15.         }
  16.         else {
  17.             if (first_time.seconds != second_time.seconds) {
  18.                 return first_time.seconds < second_time.seconds;
  19.             }
  20.         }
  21.     }
  22. }
  23.  
  24. void task3() {
  25.     int n;
  26.     cin >> n;
  27.     vector <time> time_moments(n);
  28.     for (int i = 0; i < n; i++) {
  29.         time current_time;
  30.         int current_hours, current_minutes, current_seconds;
  31.         cin >> current_hours >> current_minutes >> current_seconds;
  32.         current_time.hours = current_hours;
  33.         current_time.minutes = current_minutes;
  34.         current_time.seconds = current_seconds;
  35.         time_moments[i] = current_time;
  36.     }
  37.     stable_sort(time_moments.begin(), time_moments.end(), time_compare);
  38.     for (auto current_time : time_moments) {
  39.         cout << current_time.hours << " " << current_time.minutes << " " << current_time.seconds << endl;
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement