Advertisement
Guest User

Sắp xếp các điểm giảm theo hoành độ x

a guest
Apr 19th, 2014
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4. typedef struct point{
  5.     int x, y;
  6. };
  7.  
  8. int n;
  9. point a[1000];
  10.  
  11. void getData()
  12. {
  13.     cin >> n;
  14.     for(int i=1; i<=n; i++)
  15.         cin >> a[i].x >> a[i].y;
  16. }
  17.  
  18. void inMang()
  19. {
  20.     for(int i=1; i<=n; i++)
  21.         cout << a[i].x << ", " << a[i].y << endl;
  22. }
  23.  
  24. bool _comp(point a, point b){
  25.     return a.x > b.x;
  26. }
  27.  
  28. int main()
  29. {
  30.     getData();
  31.     // Do mang danh so tu` 1..n
  32.     cout << "Truoc khi sx" << endl;
  33.     inMang();
  34.     sort(a+1, a+(n+1), _comp);
  35.     cout << "Sau khi sx" << endl;
  36.     inMang();
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement