fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. struct point{
  7. int index;
  8. int x;
  9. int y;
  10. };
  11.  
  12. bool comp1(const point& p1,const point& p2){
  13. if(p1.x<p2.x)
  14. return true;
  15. if(p1.x==p2.x){
  16. if(p1.y<p2.y)
  17. return true;
  18. return false;
  19. }
  20.  
  21. return true;
  22. }
  23.  
  24. bool comp2(const point &p1,const point &p2){
  25. if(p1.y<p2.y)
  26. return true;
  27. if(p1.y==p2.y){
  28. if(p1.x<p2.x)
  29. return true;
  30. }
  31. return false;
  32. }
  33.  
  34. int main() {
  35. int n;
  36. vector<point> px,py;
  37. cin>>n;
  38. point p;
  39. for(int i=0;i<n;i++){
  40. cin>>p.x>>p.y;
  41. p.index = i+1;
  42. px.push_back(p);
  43. py.push_back(p);
  44.  
  45. }
  46.  
  47. std::cout << "input:\n";
  48. for(const auto& p : px)
  49. cout << p.x << " " << p.y << "\t ";
  50. cout<<endl;
  51.  
  52. sort(px.begin(),px.end(),comp1);
  53. sort(py.begin(),py.end(),comp2);
  54.  
  55. std::cout << "increasing x, y:\n";
  56. vector<point>::iterator it;
  57. for(it=px.begin();it!=px.end();it++)
  58. cout<<it->x<<" "<<it->y<<"\t ";
  59. cout<<endl;
  60.  
  61. std::cout << "increasing y, x:\n";
  62. for(it=py.begin();it!=py.end();it++)
  63. cout<<it->x<<" "<<it->y<<"\t ";
  64. cout<<endl;
  65. }
  66.  
  67.  
Success #stdin #stdout 0s 3464KB
stdin
3
2 0
1 1
1 0
stdout
input:
2 0	   1 1	   1 0	   
increasing x, y:
1 0	   1 1	   2 0	   
increasing y, x:
1 0	   2 0	   1 1