zoukankan      html  css  js  c++  java
  • c++ stl pair

    c++中的pair其实也并没什么软用,

    但出于对知识的热爱,就在此瞎比比了,

    c++ 文化博大精深,千奇百怪,无奇不有,

    于是就有了pair这玩意,

    pair的定义:

    pair<string,int> p;

    pair<int ,int > p;

    pair<double,int> p;

    。。。

    由于pair定义太繁琐于是乎,

    typedef pair<int,int> pr;

    加上这玩意定义就可变成,

    pr +名字

    是不是很神奇,

    其实pair完全可以写个node定义,

    且pair的排序是先按fist在按second。

    p.first  p.second

    附上pair的代码,

     

     
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cmath>
     4 #include<cstring>
     5 #include<algorithm>
     6 #define LL long long
     7 #define rep(i,a,b) for (int i=a;i<=b;i++)
     8 #define per(i,a,b) for (int i=a;i>=b;i--)
     9 #define inf 1<<29
    10 #define clr(i,c) memset(i,c,sizeof(i))
    11 using namespace std;
    12 inline int read(){
    13     int x=0,f=1; char ch=getchar();
    14     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    15     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} 
    16     return x*f; 
    17 }
    18 pair<int,int>a[1000];
    19 int n;
    20 int main()
    21 {
    22    n=read();
    23    rep(i,1,n) a[i].first=read(),a[i].second=i;
    24    a[1]=make_pair(1,1);
    25    sort(a+1,a+n+1);
    26    rep(i,1,n)printf("%d %d
    ",a[i].first,a[i].second);
    27 }
    View Code




  • 相关阅读:
    在已安装的PHP版本之间切换
    LDAP系列(一)完整的 LDAP + phpLDAPadmin安装部署流程
    如何关闭Windows自动更新
    win10安装SDK、JAVA、Python配置环境变量
    怎么看懂接口文档
    全面解析 Postman 工具
    API接口监控
    jmeter面试题
    Navicat for MySQL 连接数据库
    Linux系统
  • 原文地址:https://www.cnblogs.com/SXia/p/6747785.html
Copyright © 2011-2022 走看看