首页 > 其他 > 详细

sort运用

时间:2020-01-13 19:45:41      阅读:71      评论:0      收藏:0      [点我收藏+]
#include<iostream>
#include<algorithm>
#include<cstdio> 
using namespace std;
struct Node{
    int x,y;
}a[100];
int n;
//比较函数 
int cmp(Node a,Node b){
    if(a.x==b.x)return a.y<b.y;
    return a.x<b.x;
} 
void Scanf(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i].x>>a[i].y;
    }
}
void Print(){
    for(int i=0;i<n;i++){
        cout<<a[i].x<<" "<<a[i].y<<endl;
    }
}
int main(){
//    freopen("text1.txt","r",stdin);
    Scanf();
    sort(a,a+n,cmp);
    Print();
//    fclose(stdin);
    return 0;
}

sort运用

原文:https://www.cnblogs.com/yifeianyi/p/12188687.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!