c++ 返回指定元素连续相等的位置索引(equal_range)
2024-10-12 05:56:46
#include <iostream> // cout
#include <algorithm> // equal_range, sort
#include <vector> // vector
using namespace std;
bool mygreater (int i,int j) { return (i>j); } int main () {
int myints[] = {,,,,,,,};
vector<int> v(myints,myints+); // 10 20 30 30 20 10 10 20
pair<vector<int>::iterator,vector<int>::iterator> bounds; bounds=equal_range (v.begin(), v.end(), );
cout << "bounds at positions " << (bounds.first - v.begin());
cout << " and " << (bounds.second - v.begin()) << '\n'; // using default comparison:
sort (v.begin(), v.end()); // 10 10 10 20 20 20 30 30
bounds=equal_range (v.begin(), v.end(), ); // ^ ^ cout << "bounds at positions " << (bounds.first - v.begin());
cout << " and " << (bounds.second - v.begin()) << '\n'; // using "mygreater" as comp:
sort (v.begin(), v.end(), mygreater); // 30 30 20 20 20 10 10 10
bounds=equal_range (v.begin(), v.end(), , mygreater); // ^ ^ cout << "bounds at positions " << (bounds.first - v.begin());
cout << " and " << (bounds.second - v.begin()) << '\n'; return ;
}
最新文章
- 用";hosting.json";配置ASP.NET Core站点的Hosting环境
- Oracle SQL explain/execution Plan
- 安装R语言扩展包diveRsity-1
- ListFragment创建及其生命周期
- openssl_final学习总结
- percona-toolkit工具包的使用教程
- iOS语音播放之切换听筒和扬声器的方法解决方案
- Hibernate项目里配置环境时,jar包配置不当会对测试结果产生影响。
- html 标签释义
- 【Python中if __name__ == &#39;__main__&#39;: 的解析】
- python中的线程技术
- 单例模式实例&;多线程应用
- Eclipse markers窗口使用
- Tomcat实战-调优方案
- HDFS的客户端操作
- javascript数据结构与算法--二叉树(插入节点、生成二叉树)
- ubuntu16.04下安装opencv-nonfree
- 网络基础 04_IP编址
- PHPStrom 里修改Emmet对php的自动扩展
- Hdu2433 Travel
热门文章
- Message Flood(map)
- 连接数据库工具类DBUtil
- Linux系统——PXE高效能批量网络装机
- centos6更改密码
- Root :: AOAPC I: Beginning Algorithm Contests (Rujia Liu) Volume 5. Dynamic Programming
- jq 自定义标注小组件 $.widget
- python3.4学习笔记(五) IDLE显示行号问题,插件安装和其他开发工具介绍
- web前端----html表单操作
- NSDictionary打印编码改中文的方法
- MySQL Crash Course #18# Chapter 26. Managing Transaction Processing