fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct unsortedtime {
  5. int hours;
  6. int minutes;
  7. int seconds;
  8. };
  9.  
  10. bool operator > (const unsortedtime &a, const unsortedtime &b) {
  11. bool res = false;
  12. if (a.hours > b.hours) res = true;
  13. else if (a.hours == b.hours) {
  14. if (a.minutes > b.minutes) res = true;
  15. else if (a.minutes == b.minutes) {
  16. if (a.seconds > b.seconds) res = true;
  17. }
  18. }
  19. return res;
  20. };
  21.  
  22. int main() {
  23. int n;
  24. cin >> n;
  25. unsortedtime *a = new unsortedtime[n];
  26. for (int i = 0; i < n; i++) {
  27. cin >> a[i].hours >> a[i].minutes >> a[i].seconds;
  28. }
  29. for (int k = 2; k <= n; k++) {
  30. for (int i = 0; i <= n - k; i++) {
  31. if (a[i] > a[i + 1]) {
  32. swap(a[i], a[i + 1]);
  33. }
  34. }
  35. }
  36. for (int i = 0; i < n; i++) {
  37. cout << a[i].hours << " " << a[i].minutes << " " << a[i].seconds << endl;
  38. }
  39. return 0;
  40. }
Success #stdin #stdout 0s 15240KB
stdin
3
23 56 45
21 45 54
6 45 23
stdout
6 45 23
21 45 54
23 56 45