Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- struct rational{
- int num;
- int den;
- };
- void swap(rational& a, rational& b){
- rational c = a;
- a = b;
- b = c;
- }
- void bubbl(vector<rational>& v){
- int k = v.size()-1;
- bool sorted = false;
- while (not sorted){
- sorted = true;
- for (int i = 0; i < k; ++i){
- if (v[i].num * v[i+1].den > v[i+1].num * v[i].den){
- swap(v[i], v[i + 1]);
- sorted = false;
- }
- }
- --k;
- }
- }
- int main() {
- int n;
- int aux = 0;
- while(cin >> n){
- if (aux != 0) cout << endl;
- ++aux;
- vector<rational> v(n);
- for (int i = 0; i < n; ++i){
- cin >> v[i].num >> v[i].den;
- }
- // SORTING
- bubbl(v);
- for (int i = 0; i < n; ++i){
- cout << v[i].num << '/' << v[i].den << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement