fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define M 100005
  4.  
  5. struct ps
  6. {
  7. long long tu, mau;
  8. };
  9.  
  10. ps a[M];
  11. int n;
  12.  
  13. void rutgon(ps &x)
  14. {
  15. if(x.mau<0)
  16. {
  17. x.mau = -x.mau;
  18. x.tu = -x.tu;
  19. }
  20. long long tam = __gcd(x.tu, x.mau);
  21. x.tu/=tam, x.mau/=tam;
  22. }
  23.  
  24. bool cmp(ps x, ps y)
  25. {
  26. return x.tu * y.mau < x.mau * y.tu;
  27. }
  28.  
  29. int main()
  30. {
  31. cin >> n;
  32. for(int i = 0; i < n; i++)
  33. {
  34. cin >> a[i].tu >> a[i].mau;
  35. rutgon(a[i]);
  36. }
  37. sort(a, a + n, cmp);
  38. for(int i = 0; i < n; i++)
  39. cout << a[i].tu << ' ' << a[i].mau << '\n';
  40. }
  41.  
Success #stdin #stdout 0.01s 5276KB
stdin
5
2 4
1 3
1 4
5 6
1 10
stdout
1 10
1 4
1 3
1 2
5 6