fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. struct Time {
  7. int hours;
  8. int minutes;
  9. int seconds;
  10.  
  11. };
  12.  
  13. bool compare(Time a, Time b) {
  14. if (a.hours == b.hours) {
  15. if (a.minutes == b.minutes) {
  16. return a.seconds < b.seconds;
  17. }
  18. else{
  19. return a.minutes < b.seconds;
  20. }
  21. }
  22. else {
  23. return a.hours < b.hours;
  24. }
  25. }
  26.  
  27. int main() {
  28. int n;
  29. cin >> n;
  30. vector<Time> time;
  31. while (n--) {
  32. Time temp;
  33. cin >> temp.hours >> temp.minutes >> temp.seconds;
  34. time.push_back(temp);
  35. }
  36. sort(time.begin(), time.end(), compare);
  37. for (auto c : time) {
  38. cout << c.hours << ' ' << c.minutes << ' ' << c.seconds << '\n';
  39. }
  40. }
Success #stdin #stdout 0.01s 5464KB
stdin
4
10 20 30
7 30 00
23 59 59
13 30 30
stdout
7 30 0
10 20 30
13 30 30
23 59 59