小编Mat*_*ode的帖子

多集索引查找

我有一个多组 int 。C++

multiset<int>t;
Run Code Online (Sandbox Code Playgroud)

我需要找到大于等于 val 的第一个元素的位置。我为此使用了lower_bound

multiset<int>::iterator it= lower_bound(t[n].begin(), t[n].end(), val);
Run Code Online (Sandbox Code Playgroud)

但是找不到从多集开始的相对位置。正如 The Cplusplus.com 建议使用...作为向量。

// lower_bound/upper_bound example
#include <iostream>     // std::cout
#include <algorithm>    // std::lower_bound, std::upper_bound, std::sort
#include <vector>       // std::vector

int main () {
  int myints[] = {10,20,30,30,20,10,10,20};
  std::vector<int> v(myints,myints+8);           // 10 20 30 30 20 10 10 20

  std::sort (v.begin(), v.end());                // 10 10 10 20 20 20 30 30

  std::vector<int>::iterator low,up;
  low=std::lower_bound (v.begin(), v.end(), 20); //          ^
  up= std::upper_bound (v.begin(), v.end(), 20); //                   ^

  std::cout …
Run Code Online (Sandbox Code Playgroud)

c++ multiset

7
推荐指数
1
解决办法
6816
查看次数

标签 统计

c++ ×1

multiset ×1