fork download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <vector>
  4.  
  5. struct date
  6. {
  7. int year;
  8. int month;
  9. int day;
  10. };
  11.  
  12. std::istream& operator>>(std::istream& in, date& d)
  13. {
  14. return in >> d.year >> d.month >> d.day;
  15. }
  16.  
  17. std::ostream& operator<<(std::ostream& out, const date& d)
  18. {
  19. return out << d.year << ' ' << d.month << ' ' << d.day;
  20. }
  21.  
  22. int main()
  23. {
  24. std::vector<date> data;
  25. date temp;
  26. while(std::cin >> temp)
  27. data.push_back(temp);
  28. for(const auto d: data)
  29. std::cout << d << '\n';
  30. std::cout << '\n';
  31. //Sort by year
  32. std::sort(data.begin(), data.end(), [](const date& lhs, const date& rhs)
  33. { return lhs.year < rhs.year; });
  34. for(const auto d: data)
  35. std::cout << d << '\n';
  36. }
Success #stdin #stdout 0s 3420KB
stdin
2010 12 25
2011 01 15
2010 11 01 
stdout
2010 12 25
2011 1 15
2010 11 1

2010 12 25
2010 11 1
2011 1 15