http://classfoo.com/ccby/article/cIBahI

  1. #include <iostream>
  2. #include <algorithm>
  3. #include <functional>
  4. #include <vector>
  5. // 用在此处是为了方便简洁, 在实际编程中慎用
  6. using namespace std;
  7. void main()
  8. {
  9. int iarray[] = { , , , , , , , , , , };
  10. vector<int> foo1(iarray, iarray + sizeof(iarray) / sizeof(int));
  11. int iarray1[] = { , };
  12. vector<int> foo2(iarray1, iarray1 + sizeof(iarray1) / sizeof(int));
  13. int iarray2[] = { , };
  14. vector<int> foo3(iarray2, iarray2 + sizeof(iarray2) / sizeof(int));
  15. int iarray3[] = { , , , , , , , , , , };
  16. vector<int> foo4(iarray3, iarray3 + sizeof(iarray3) / sizeof(int));
  17.  
  18. //找出foo1之中相邻元素值相等的第一个元素
  19. cout << *adjacent_find(foo1.begin(), foo1.end()) << endl; //6
  20.  
  21. //找出foo1之中元素值为6的元素个数
  22. cout << count(foo1.begin(), foo1.end(), ) << endl; //3
  23.  
  24. //找出foo1之中小于7的元素个数
  25. cout << count_if(foo1.begin(), foo1.end(), bind2nd(less<int>(), )) << endl;//9
  26.  
  27. //找出foo1之中元素值为4的第一个元素所在位置的元素
  28. cout << *find(foo1.begin(), foo1.end(), ) << endl;//4
  29.  
  30. //找出foo1之中大于2的第一个元素所在位置的元素
  31. cout << *find_if(foo1.begin(), foo1.end(), bind2nd(greater<int>(), ))//3
  32. << endl;
  33.  
  34. //找出foo1之中子序列foo2所出现的最后一个位置,再往后3个位置的元素
  35. cout << *(find_end(foo1.begin(), foo1.end(), foo2.begin(),//8
  36. foo2.end()) + ) << endl;
  37.  
  38. //找出foo1之中子序列foo2所出现的第一个位置,再往后3个位置的元素
  39. cout << *(find_first_of(foo1.begin(), foo1.end(), foo2.begin(),//7
  40. foo2.end()) + ) << endl;
  41.  
  42. //子序列foo3在foo1中出现的起点位置元素
  43. cout << *search(foo1.begin(), foo1.end(), foo3.begin(), foo3.end())//5
  44. << endl;
  45.  
  46. //查找连续出现3个6的起点位置元素
  47. cout << *search_n(foo1.begin(), foo1.end(), , , equal_to<int>()) << endl;//6
  48.  
  49. //判断两个区间foo1和foo4相等否(0为假,1为真)
  50. cout << equal(foo1.begin(), foo1.end(), foo4.begin()) << endl;//0
  51.  
  52. //查找区间foo4在foo1中不匹配点的位置
  53. pair<std::vector<int>::iterator, std::vector<int>::iterator>result =
  54. mismatch(foo1.begin(), foo1.end(), foo4.begin());
  55. cout << result.first - foo1.begin() << endl;//6
  56. }

vector 搜索的更多相关文章

  1. Longest common prefix | leetcode

    Write a function to find the longest common prefix string amongst an array of strings. 思路:要去是寻找字符串ve ...

  2. NAACL 2019 字词表示学习分析

    NAACL 2019 表示学习分析 为要找出字.词.文档等实体表示学习相关的文章. word embedding 搜索关键词 word embedding Vector of Locally-Aggr ...

  3. 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 ...

  4. 在WinDbg中显示和搜索std::vector内容

    WinDbg从来都不擅长可视化.尽管Visual Studio一直都有autoexp.dat,而且最近还出现了本机调试器可视化工具,但WinDbg用户不得不满足于转储内存区域和搜索内存来识别模式.另一 ...

  5. ES搜索排序,文档相关度评分介绍——Vector Space Model

    Vector Space Model The vector space model provides a way of comparing a multiterm query against a do ...

  6. geotrellis使用(二十六)实现海量空间数据的搜索处理查看

    目录 前言 前台实现 后台实现 总结 一.前言        看到这个题目有人肯定会说这有什么可写的,最简单的我只要用文件系统一个个查找.打开就可以实现,再高级一点我可以提取出所有数据的元数据,做个元 ...

  7. [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 ...

  8. [LeetCode] Search in Rotated Sorted Array II 在旋转有序数组中搜索之二

    Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? Would this ...

  9. [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 ...

随机推荐

  1. 「LibreOJ#516」DP 一般看规律

    首先对于序列上一点,它对答案的贡献只有与它的前驱和后驱(前提颜色相同)构成的点对, 于是想到用set维护每个颜色,修改操作就是将2个set暴力合并(小的向大的合并),每次插入时更新答案即可 颜色数要离 ...

  2. mysql学习第三天练习(多表连接)

    -- 多表连接 -- 写一条查询语句,查询员工姓名.部门名称.工作地点 select ename,dname,loc from emp,dept where emp.deptno = dept.dep ...

  3. linux安装软件的几种方式(kali平台)和一些实用的软件(持续更新)

    安装软件前我们先更改镜像源,编辑 /etc/apt/sources.list 文件, 在文件最前面添加以下条目: #中科大更新源 deb https://mirrors.ustc.edu.cn/kal ...

  4. 9 udp广播

    udp有广播  写信 tcp没有广播·  打电话 #coding=utf-8 import socket, sys dest = ('<broadcast>', 7788) # 创建udp ...

  5. LeetCode:11. ContainerWithWater(Medium)

    原题链接:https://leetcode.com/problems/container-with-most-water/description/ 题目要求:给定n个非负整数a1,a2,...,an  ...

  6. 创龙TMS320C6748开发板串口和中断学习笔记

    1. 硬件上,底板有2个串口,UART1和UART2(使用了MAX3232电平转换芯片),其中UART2也可以转RS485的. 2. 看下数据手册部分,不过一直不理解过采样的意思,16字节的FIFO ...

  7. lua基础知识笔记

    一.lua中的数据类型 1.数值 a = 1 b = 1.2 2.字符串 c = "hello world" 3.布尔 d = true f = false 4.表(Table) ...

  8. Linux硬盘性能检测

    对于现在的计算机来讲,整个计算机的性能主要受磁盘IO速度的影响,内存.CPU包括主板总线的速度已经很快了. 基础检测方法 1.dd命令 dd命令功能很简单,就是从一个源读取数据以bit级的形式写到一个 ...

  9. MySQL数据库性能优化专题

    摘录: 书:<MySQL性能调优与架构设计> 一个系列: (按顺序排一下) MySQL 数据库性能优化之缓存参数优化 http://isky000.com/database/mysql-p ...

  10. 第二十二篇 正在表达式 re模块

    re模块****** 就本质而言,正则表达式时一种小型的,高度专业化的编程语言,在python里,它内嵌在python中,并通过re模块实现.正则表达式模式被编译成一系列的字节码.然后用C编写的匹配引 ...