fork(1) download
  1. #include <iostream>
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4.  
  5. void qsortfirst(pair<int,int> p[],int low,int up){
  6.  
  7. if(low>=up)
  8. return;
  9. pair<int,int> temp;
  10. int i=low+1,j=up,pivot=p[i].first;
  11. while(i<=j){
  12. while(p[i].first<pivot)
  13. i++;
  14. while(p[j].first>pivot)
  15. j--;
  16. if(i<j){
  17. temp=p[i];
  18. p[j]=p[i];
  19. p[i]=temp;
  20. j--;
  21. i++;
  22. }
  23. else if(i==j)
  24. i++;
  25. }
  26. temp=p[j];
  27. p[j]=p[low];
  28. p[low]=temp;
  29. qsortfirst(p,low,j-1);
  30. qsortfirst(p,j+1,up);
  31. }
  32.  
  33. int main() {
  34. // your code goes here
  35. pair<int,int> p[5];
  36. for(int i=0;i<5;i++)
  37. cin>>p[i].first>>p[i].second;
  38. qsortfirst(p,0,5);
  39. for(int i=0;i<5;i++)
  40. cout<<p[i].first<<" "<<p[i].second;
  41. return 0;
  42. }
  43.  
Success #stdin #stdout 0s 3472KB
stdin
1 3
2 4
4 5
3 2
1 6
stdout
2 41 33 24 53 2