vector 搜索
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
}
vector 搜索的更多相关文章
- Longest common prefix | leetcode
Write a function to find the longest common prefix string amongst an array of strings. 思路:要去是寻找字符串ve ...
- NAACL 2019 字词表示学习分析
NAACL 2019 表示学习分析 为要找出字.词.文档等实体表示学习相关的文章. word embedding 搜索关键词 word embedding Vector of Locally-Aggr ...
- Lucene in action 笔记 term vector——针对特定field建立的词频向量空间,不存!不会!影响搜索,其作用是告诉我们搜索结果是“如何”匹配的,用以提供高亮、计算相似度,在VSM模型中评分计算
摘自:http://makble.com/what-is-term-vector-in-lucene given a document, find all its terms and the posi ...
- 在WinDbg中显示和搜索std::vector内容
WinDbg从来都不擅长可视化.尽管Visual Studio一直都有autoexp.dat,而且最近还出现了本机调试器可视化工具,但WinDbg用户不得不满足于转储内存区域和搜索内存来识别模式.另一 ...
- ES搜索排序,文档相关度评分介绍——Vector Space Model
Vector Space Model The vector space model provides a way of comparing a multiterm query against a do ...
- geotrellis使用(二十六)实现海量空间数据的搜索处理查看
目录 前言 前台实现 后台实现 总结 一.前言 看到这个题目有人肯定会说这有什么可写的,最简单的我只要用文件系统一个个查找.打开就可以实现,再高级一点我可以提取出所有数据的元数据,做个元 ...
- [LeetCode] Search a 2D Matrix II 搜索一个二维矩阵之二
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...
- [LeetCode] Search in Rotated Sorted Array II 在旋转有序数组中搜索之二
Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? Would this ...
- [LeetCode] Search a 2D Matrix 搜索一个二维矩阵
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...
随机推荐
- py函数初识
一. 什么是函数 1. 我们到目前为止, 已经可以完成一些软件的基础功能了. 那么我们来完成这样一个功能: 约x print("拿出手机") print("打开陌&quo ...
- HyperLedger Fabric 1.4 关键技术(6.4)
本节介绍从最底层的账本开始,逐一讲解账本的结构和存储.智能合约的编写和部署.通道的操作.节点的背书和提交.排序的共识和客户端SDK的接口调用,与交易流程顺序相反,由里及表的说明Fabric最关键的技术 ...
- ABAP CDS ON HANA-(11)ABAP CDSでの関連付け
Association in ABAP CDS An association in CDS view joins different data sources. Defining and using ...
- python2.7练习小例子(十三)
13):题目:将一个正整数分解质因数.例如:输入90,打印出90=2*3*3*5. 程序分析:对n进行分解质因数,应先找到一个最小的质数k,然后按下述步骤完成.(1)如果这个质数恰等于 ...
- @Transactional spring 事务(转载)
原文链接: http://www.cnblogs.com/sweetchildomine/p/6978037.html?utm_source=itdadao&utm_medium=referr ...
- 2002: [Hnoi2010]Bounce 弹飞绵羊
2002: [Hnoi2010]Bounce 弹飞绵羊 https://www.lydsy.com/JudgeOnline/problem.php?id=2002 分析: 绵羊在弹飞的路径中相当于一棵 ...
- axios应用
Skip to content Features Business Explore Marketplace Pricing Sign in or Sign up Watch929 St ...
- 算法搬运之BFPRT算法
原文连接:http://noalgo.info/466.html BFPRT算法,又称为中位数的中位数算法,由5位大牛(Blum . Floyd . Pratt . Rivest . Tarjan)提 ...
- 解析·NOIP·冷门 CLZ最小环
赐予我力量,去改变我所能改变的;赐予我勇气,去接受我不能改变的;并赐予我智慧,去分辨这两者. -----安东尼达斯 NOIP的图论题中有一部分是跟图上的环有关的.蒟蒻的我在USACO上刷题时发现了一种 ...
- 实用的placeholder插件,兼容IE下的placeholder,jquery插件
placeholder在IE下无法兼容 ,下面的插件很好的处理了这个问题,拿去不谢 /* * jQuery placeholder, fix for IE6,7,8,9 * @website itmy ...