Permutation - Sorting Pairs

745 词

题目描述

Sorting Pairs Write a program which print coordinates (xi,yi) of given n points on the plane by the following criteria.

 first by x-coordinate in case of a tie, by y-coordinate

输入

The input is given in the following format. 

n

x0 y0 

x1 y1

 : 

xn−1 yn−1

 In the first line, the number of points n is given. In the following n lines, coordinates of each point are given.

输出

Print coordinate of given points in order.

样例输入

1
2
3
4
5
6
5
4 7
5 5
2 3
6 8
2 1

样例输出

1
2
3
4
5
2 1
2 3
4 7
5 5
6 8

提示

1≤n≤100,000

 −1,000,000,000≤xi,yi≤1,000,000,000

题解

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <set>
#include <iostream>
using namespace std;
int main(){
int n;
cin>>n;
multiset<pair<int,int>> m;
while(n--){
int i,j;
cin>>i>>j;
m.insert(pair<int,int>(i,j));
}
for(auto &i:m){
printf("%d %d\n",i.first,i.second);
}
}