sort运用

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cstdio> 
 4 using namespace std;
 5 struct Node{
 6     int x,y;
 7 }a[100];
 8 int n;
 9 //比较函数 
10 int cmp(Node a,Node b){
11     if(a.x==b.x)return a.y<b.y;
12     return a.x<b.x;
13 } 
14 void Scanf(){
15     cin>>n;
16     for(int i=0;i<n;i++){
17         cin>>a[i].x>>a[i].y;
18     }
19 }
20 void Print(){
21     for(int i=0;i<n;i++){
22         cout<<a[i].x<<" "<<a[i].y<<endl;
23     }
24 }
25 int main(){
26 //    freopen("text1.txt","r",stdin);
27     Scanf();
28     sort(a,a+n,cmp);
29     Print();
30 //    fclose(stdin);
31     return 0;
32 }

 

posted @ 2017-08-14 07:39 逸非安逸 阅读(...) 评论(...) 编辑 收藏