c++ set 从小到大排列点坐标

Modified on: Wed, 27 Mar 2019 20:25:00 +0800 热度: 1,300 度

#include <bits/stdc++.h>
using namespace std;
struct point{
    int x,y;
    bool operator<(const point &r) const
    {
        if(x==r.x)
            return y<r.y;
        else
            return x<r.x;
    }
};
int main(int argc, const char * argv[]) {
    int t;
    set<point> v;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        point temp;
        cin>>temp.x>>temp.y;
        v.insert(temp);
    }
    for(set<point>::iterator it =v.begin();it!=v.end();it++)
    {
        cout << "("<< it -> x << "," << it -> y << ")" << endl;
    }
    return 0;
}

添加新评论