首页 > 编程语言 >C++ uppper_bound 使用

C++ uppper_bound 使用

时间:2023-02-15 09:22:25浏览次数:48  
标签:map uppper int bound C++ include

 

map 的key,默认按照从小到达排序;

upper_bound(4),

 

 

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int main()
{
    map<int, string>  mapA;   //默认从小到大排序(升序)

    for(int i=0;i<10;++i)
    {
        string str;
        str ="henry" + std::to_string(10-i);
        mapA[i]=str;
        cout <<"key:"<<i<<",val:"<<mapA[i]<<endl;
    }

 
    auto upIt = mapA.upper_bound(4);
    auto lowIt = mapA.lower_bound(4);

    cout <<"---------out put upper_bound(4) :"<<endl;
    for(auto it = mapA.begin(); it!=upIt; ++it)
    {
        cout <<"key:"<< it->first<<",val:"<<it->second<<endl;// 0,1,2,3,4
    }
    cout <<endl;

    cout <<"---------out put lower_bound(4):"<<endl;
    for(auto it = lowIt; it!=mapA.end(); ++it)
    {
        cout <<"key:"<< it->first<<",val:"<<it->second<<endl;//4,5,6,7,8,9
    }
    cout <<endl;

    cout <<"-----finished -----"<<endl;
    return 0;
}

 

 

 

 

 

标签:map,uppper,int,bound,C++,include
From: https://www.cnblogs.com/music-liang/p/17121527.html

相关文章

  • 实现C++和C的混合编程
    实现C++和C的混合编程在C++出现之前,很多实用的功能都是用C语言开发的,很多底层的库也是用C语言编写的。这意味着,如果能在C++代码中兼容C语言代码,无疑能极大地提......
  • C/C++程序设计课程设计[2023-02-15]
    C/C++程序设计课程设计[2023-02-15]程序设计课程设计要求1、课程设计分组合作完成,每个小组最多3人。2、每组成员(不得超过3人)分工合作完成一个课程设计题目,每个人的任......
  • C++类的组合
    title:C++类的组合案例date:2022-05-1819:07:35tags:C++category:cpp参考书籍:C++PrimerEssentialC++编译器:gcc/g++C++类的组合什么是类的组合类的组合就是以......
  • 高效字符串匹配算法——BM 算法详解(C++)
    定义BM算法是由Boyer和Moore两人提出的一种高效的字符串匹配算法,被认为是一种亚线性算法(即平均的时间复杂度低于线性级别),其时间效率在一般情况下甚至比KMP还要快3......
  • c++通过http协议校时
    由于IP黑白名单的限制,我们能访问的ip和域名资源非常有限,现将通过http协议授时方法整理如下: #include<cstdio>#include<string.h>#include<curl/curl.h>#inclu......
  • 【opencv c++】实现yolov5部署onnx模型完成目标检测
    总代码#include<fstream>#include<sstream>#include<iostream>#include<opencv2/dnn.hpp>#include<opencv2/imgproc.hpp>#include<opencv2/highgui.hpp>usin......
  • c++函数与结构
    当结构比较小时,按值传递结构最合理。传递2个值结构体,返回一个结构体,返回的结构体中的成员是参数各成员的和。#include<cstring>usingnamespacestd;structthings{i......
  • C/C++读入含有空格的字符串
    好久之前遇到gets()不准用的情况,所以稍稍参考了一下网上的方法,整理一下。 charst[maxn];strings;1、gets(st);2、scanf("%[^\n]",st);3、getline(cin,s);......
  • C++PrimerPlus中文第六版第11章编程练习答案
    1、//vector.h#ifndefVECTOR_H_#defineVECTOR_H_#include<iostream>namespaceVECTOR{classVector{public:enumMode{RECT,POL};......
  • C/C++产品销售统计系统[2023-02-14]
    C/C++产品销售统计系统[2023-02-14]题目15: 产品销售统计一家公司生产五种产品,每种产品在一个月内每周的生产数量和销售价格都要记录下来。下面是一个二维的表格,表格的每......