fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. struct drob
  9. {
  10. int m, n;
  11. };
  12.  
  13. bool f(drob dr1, drob dr2)
  14. {
  15. if (dr1.n != dr2.n)
  16. return dr1.m * dr2.n < dr2.m * dr1.n;
  17. return dr1.m < dr2.m;
  18. }
  19.  
  20. int main()
  21. {
  22. int k, m, n;
  23. cin >> k;
  24. vector<drob> v(k);
  25. for (int i = 0; i < k; i++)
  26. {
  27. cin >> m >> n;
  28. v[i].m = m;
  29. v[i].n = n;
  30. }
  31. sort(v.begin(), v.end(), f);
  32. for (auto e : v)
  33. cout << e.m << '/' << e.n << endl;
  34. }
Success #stdin #stdout 0s 5632KB
stdin
Standard input is empty
stdout
Standard output is empty