#18981: struct


michaelwang920324@gmail.com (王少甫)

School : 臺北市私立復興實驗高級中學
ID : 89781
IP address : [175.159.121.189]
Last Login :
2021-09-12 15:13:38
a915. 二维点排序 | From: [140.122.107.162] | Post Date : 2019-08-21 20:21

#include<bits/stdc++.h>

using namespace std;

struct position{
int x;
int y;
};

int main(){
int i = 0;
int n;
cin>>n;
int m = n;

struct position p[1000], temp;

int a, b;
while(n--){
cin>>p[i].x>>p[i].y;
i++;
}
for(int j = 0; j < m-1; j++){
for(int k = 0; k < m-1-j; k++){
if(p[k].x > p[k+1].x){
swap(p[k], p[k+1]);
}
if((p[k].x == p[k+1].x) and (p[k].y) > p[k+1].y){
swap(p[k], p[k+1]);
}
}
}

for(int j = 0; j < m; j++){
cout<<p[j].x<<" "<<p[j].y<<endl;
}



}

 
ZeroJudge Forum