Advertisement
kachamaka

Untitled

Mar 9th, 2022
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. struct Date{
  6. int day;
  7. int month;
  8. int year;
  9. int index;
  10.  
  11. bool operator<(const Date& d) const {
  12. if(year < d.year) return true;
  13. else if( year > d.year) return false;
  14. else{
  15. if(month < d.month) return true;
  16. else if(month > d.month) return false;
  17. else{
  18. if(day < d.day) return true;
  19. return false;
  20. }
  21. }
  22. }
  23.  
  24. Date(){
  25.  
  26. }
  27.  
  28. Date(int d, int m, int y, int i): day(d), month(m), year(y), index(i) {
  29.  
  30. }
  31. };
  32.  
  33. void gnomeSort(Date arr[], int n) {
  34. int index = 0;
  35.  
  36. while (index < n) {
  37. if (index == 0)
  38. index++;
  39. if (arr[index] < arr[index - 1]) {
  40. std::swap(arr[index], arr[index - 1]);
  41. index--;
  42. } else {
  43. index++;
  44. }
  45. }
  46. return;
  47. }
  48. // std::vector<Date> dates;
  49.  
  50. int main() {
  51. Date dates[100] = {};
  52. int n;
  53. scanf("%d", &n);
  54. for(int i = 0; i < n; ++i){
  55. int d, m, y;
  56. scanf("%d.%d.%d", &d, &m, &y);
  57. dates[i] = Date(d, m, y, i + 1);
  58. }
  59.  
  60. // std::sort(dates, dates + n, [](const Date& a, const Date& b){
  61. // if(a < b){
  62. // return true;
  63. // }
  64. // return false;
  65. // });
  66. gnomeSort(dates, n);
  67. for(int i = 0; i < n; ++i){
  68. printf("%d\n", dates[i].index);
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement