题号: 10251
时限:1000ms
限制内存:32768KB
题目:
坐标排序
描述
给出n个坐标,输出n个排完序的坐标。
输入格式
第一行是一个整数n。(1<=n<=1000)
接下来n行每行包括两个整数。每个整数的范围均在int型范围内。
输出格式
对这n个坐标,按x坐标升序排序,如果x坐标相等,则按y坐标升序排序。
输出n行排完序的坐标。
输入样例
7
1 2
1 3
2 3
6 8
4 2
1 3
2 5
输出样例
1 2
1 3
1 3
2 3
2 5
4 2
6 8
代码
#include<iostream>
#include<algorithm>
using namespace std;
struct coordinate{
int x,y;
};
bool cmp(coordinate a,coordinate b)
{
if(a.x==b.x)
return a.y<b.y;
return a.x<b.x;
}
int main()
{
coordinate a[1005];
int n;
cin>>n;
for(int i=0;i<n;++i)
cin>>a[i].x>>a[i].y;
sort(a,a+n,cmp);
for(int i=0;i<n;++i)
cout<<a[i].x<<" "<<a[i].y<<endl;
return 0;
}