vector 搜索
2024-08-29 02:17:56
http://classfoo.com/ccby/article/cIBahI
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
// 用在此处是为了方便简洁, 在实际编程中慎用
using namespace std;
void main()
{
int iarray[] = { , , , , , , , , , , };
vector<int> foo1(iarray, iarray + sizeof(iarray) / sizeof(int));
int iarray1[] = { , };
vector<int> foo2(iarray1, iarray1 + sizeof(iarray1) / sizeof(int));
int iarray2[] = { , };
vector<int> foo3(iarray2, iarray2 + sizeof(iarray2) / sizeof(int));
int iarray3[] = { , , , , , , , , , , };
vector<int> foo4(iarray3, iarray3 + sizeof(iarray3) / sizeof(int)); //找出foo1之中相邻元素值相等的第一个元素
cout << *adjacent_find(foo1.begin(), foo1.end()) << endl; //6 //找出foo1之中元素值为6的元素个数
cout << count(foo1.begin(), foo1.end(), ) << endl; //3 //找出foo1之中小于7的元素个数
cout << count_if(foo1.begin(), foo1.end(), bind2nd(less<int>(), )) << endl;//9 //找出foo1之中元素值为4的第一个元素所在位置的元素
cout << *find(foo1.begin(), foo1.end(), ) << endl;//4 //找出foo1之中大于2的第一个元素所在位置的元素
cout << *find_if(foo1.begin(), foo1.end(), bind2nd(greater<int>(), ))//3
<< endl; //找出foo1之中子序列foo2所出现的最后一个位置,再往后3个位置的元素
cout << *(find_end(foo1.begin(), foo1.end(), foo2.begin(),//8
foo2.end()) + ) << endl; //找出foo1之中子序列foo2所出现的第一个位置,再往后3个位置的元素
cout << *(find_first_of(foo1.begin(), foo1.end(), foo2.begin(),//7
foo2.end()) + ) << endl; //子序列foo3在foo1中出现的起点位置元素
cout << *search(foo1.begin(), foo1.end(), foo3.begin(), foo3.end())//5
<< endl; //查找连续出现3个6的起点位置元素
cout << *search_n(foo1.begin(), foo1.end(), , , equal_to<int>()) << endl;//6 //判断两个区间foo1和foo4相等否(0为假,1为真)
cout << equal(foo1.begin(), foo1.end(), foo4.begin()) << endl;//0 //查找区间foo4在foo1中不匹配点的位置
pair<std::vector<int>::iterator, std::vector<int>::iterator>result =
mismatch(foo1.begin(), foo1.end(), foo4.begin());
cout << result.first - foo1.begin() << endl;//6
}
最新文章
- sudo apt-get install apache2 php7.0 php7.0-mysql mysql-server
- Spark入门实战系列--7.Spark Streaming(下)--实时流计算Spark Streaming实战
- poj 1459 多源多汇点最大流
- 短信轰炸PC版
- Kendo UI - Class 基类定义
- [cocos2dx 3.0 + iap]中文文档(转)
- Bash远程文件传输命令scp
- mysql事务、触发器、视图、存储过程、函数
- 百度地图api将可视区域定位到当前所在位置
- 欢迎进入我的个人博客 anzhan.me
- esp8266 免费wifi强推广告神器(4) 发现当前WIFI下的用户数目,IP,MAC请求http信息 在用户请求跳转后跳转
- Js元素拖拽功能实现
- 再唠叨JS模块化加载之CommonJS、AMD、CMD、ES6
- c#无边框窗体移动
- Confluence 6 访问日志脚本
- Secure Shell相关设置
- 『原创』手把手教你搭建一个实用的油耗App(一)
- angular4.0和angularJS、react.js、vue.js的简单比较
- Fiddler2 java代码拦截设置
- 折半插入排序-ACM题
热门文章
- (数据科学学习手札16)K-modes聚类法的简介&;Python与R的实现
- HDOJ 1176 免费馅饼(完全背包)
- SIMD数据并行(一)——向量体系结构
- linux c fprintf()
- lambda, 匿名函数, 变量,传参
- Delphi中Templates代码模板添加注意事项
- LeetCode:26. Remove Duplicates from Sorted Array(Easy)
- 【多校联合】(HDU6095)Rikka with Competition
- Qt Demo Http 解析网址 Openssl
- Struts2(三.用户登录状态显示及Struts2标签)