fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <ostream>
  5.  
  6. struct Coordinate
  7. {
  8. public:
  9. int x;
  10. int y;
  11.  
  12. Coordinate(int valuex, int valuey) : x(valuex), y(valuey) {}
  13. };
  14.  
  15. bool sortcomp(const Coordinate &a, const Coordinate &b)
  16. {
  17. return (a.x < b.x) || (a.y < b.y);
  18. }
  19.  
  20. bool compare(const Coordinate &a, const Coordinate &b)
  21. {
  22. return (a.x == b.x) && (a.y == b.y);
  23. }
  24.  
  25. std::ostream& operator << (std::ostream& os, const std::vector<Coordinate> &v)
  26. {
  27. for (auto it = v.begin(); it != v.end() - 1; ++it)
  28. std::cout<<"("<<it->x<<", "<<it->y<<"), ";
  29.  
  30. std::cout<<"("<<v[v.size() - 1].x<<", "<<v[v.size() - 1].y<<")";
  31. }
  32. int main()
  33. {
  34. std::vector<Coordinate> v = {{0,0}, {0,1}, {0,0}, {0,-1}, {0,-2}};
  35.  
  36. std::sort(v.begin() + 1, v.end(), sortcomp);
  37. v.erase(std::unique(v.begin() + 1, v.end(), compare), v.end());
  38.  
  39. if (v.size() > 2)
  40. {
  41. for (unsigned i = 1; i < v.size() - 1; ++i)
  42. {
  43. v.erase(v.begin() + i);
  44. i = 0;
  45. }
  46. }
  47.  
  48. std::cout<<v;
  49. }
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
(0, 0), (0, 1)