Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main(){
- int t;
- scanf("%d", &t);
- vector<int>a,b;
- for(int i=0; i<t; i++){
- int n;
- scanf("%d", &n);
- for(int j=0; j<n; j++){
- int c,d;
- scanf("%d %d", &c, &d);
- a.push_back(c), b.push_back(d);
- }
- while(1){
- int ok=0;
- for (int k=0; k<n-1; k++){
- if(a[k]>a[k+1]){
- swap(a[k], a[k+1]);
- swap(b[k], b[k+1]);
- ok=1;}
- else if(a[k]==a[k+1]){
- if(b[k]<b[k+1]){
- swap (a[k], a[k+1]);
- swap (b[k], b[k+1]);
- ok=1;}
- }
- }
- if(ok==0)break;
- }
- for(int m=0; m<n; m++){
- printf("%d %d\n", a[m], b[m]);
- }
- a.clear(), b.clear();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement