zoukankan      html  css  js  c++  java
  • nyist 8 set的应用

    #include<iostream>
    #include<set>
    #include<algorithm>
    using namespace std;


    class rect //类 声明公有
    { public:
    int bh,a,b;
    bool operator<(const rect & x) const
    {
    if(x.bh!=bh) return bh<x.bh ;
    if(x.a!=a) return a<x.a ;
    if(x.b!=b) return b<x.b ;
    return 0;
    }
    };

    #include<iostream>
    #include<set>
    #include<algorithm>
    using namespace std;


    struct rect //结构体 公有 ?
    { // ?
    int bh,a,b; // ?
    bool operator<(const rect & x) const // 运算符重载 小于号
    {
    if(x.bh!=bh) return bh<x.bh ;
    if(x.a!=a) return a<x.a ;
    if(x.b!=b) return b<x.b ;
    return 0; // 三者相等
    }
    };

    int main()
    {
    int m,n,i;
    struct rect t;
    set <rect>my;
    set <rect>::iterator it ;
    cin>>n ;
    while(n--)
    {
    cin >>m;
    while(m--)
    {
    cin>>t.bh>>t.a>>t.b ;
    if(t.a< t.b) swap(t.a,t.b);
    my.insert(t); // 插入到 set “集合”
    }
    for(it=my.begin();it!=my.end();it++)
    cout<<(*it).bh<<" "<<(*it).a<<" " <<(*it).b<<endl ;
    my.clear();

    }
    }


    ***************************************************************************************************************

    #include<iostream>
    #include<set>
    #include<iterator>
    using namespace std;
    struct Rect
    {
    int num,length,width;
    };
    bool operator<(const Rect& r1,const Rect& r2)
    {

    return r1.num<r2.num || r1.num==r2.num && r1.length<r2.length ||r1.num==r2.num&&r1.length==r2.length &&r1.width<r2.width;
    }
    istream& operator>>(istream& in,Rect& r)
    {

    in>>r.num;
    int a,b;
    cin>>a>>b;
    r.length=max(a,b);

    r.width=min(a,b);

    return in;
    }
    ostream& operator<<(ostream& out,const Rect& r)
    {
    return out<<r.num<<" "<<r.length<<" "<<r.width;
    }
    int main()
    {

    int num;

    cin>>num;

    while(num--)

    {

    set<Rect> rs;

    Rect r;

    int n;

    cin>>n;

    while(n--)

    {

    cin>>r;
    rs.insert(r);
    }

    copy(rs.begin(),rs.end(),ostream_iterator<Rect>(cout," "));

    }
    }

    极目,远眺(752284118) 15:55:13
    nyist 8一种排序: 用set自定义排序规则即可
    #include <iostream>
    #include <set>
    using namespace std;
    struct ju
    {
    int id,x,y;
    bool operator <(const ju &a)const
    {
    if(id==a.id)
    {
    if(x==a.x) return y<a.y;
    else return x<a.x;
    }
    else return id<a.id;
    }
    }tt;
    set<ju> my;
    set<ju> ::iterator it;
    int main(int argc, char *argv[])
    {
    int t,n,i,j;
    cin>>t;
    while(t--)
    {
    cin>>n; my.clear();
    for(i=0;i<n;i++)
    {
    cin>>tt.id>>tt.x>>tt.y;
    if(tt.x<tt.y) swap(tt.x,tt.y);
    my.insert(tt);
    }
    for(it=my.begin();it!=my.end();it++)
    cout<<(*it).id<<" "<<(*it).x<<" "<<(*it).y<<endl;
    }
    return 0;
    }

  • 相关阅读:
    linux 时间同步
    sublime3 install python3
    Postfix的工作原理
    MySQL启动报错
    Socket server
    自定义静态网卡配置
    Nginx 404 500
    Pymysql
    Gitlab smtp 设置
    Windows 文件自动同步共享工具
  • 原文地址:https://www.cnblogs.com/2014acm/p/3903183.html
Copyright © 2011-2022 走看看