STL algorithm算法mismatch(37)
mismatch原型:
std::mismatch
| equality (1) |
template <class InputIterator1, class InputIterator2> |
|---|---|
| predicate (2) |
template <class InputIterator1, class InputIterator2, class BinaryPredicate> |
该函数是用来查找两个序列中第一对不匹配的元素。第一个序列为[first1.last1),第二个序列从first2開始。
比如:
序列1:1,3,5,7,9
序列2:1,3,8,8,9
第一对不匹配的元素为(5,8)
假设第一个序列和第二个序列的前部全然同样,比如
1,2,3,4
1,2,3,4,5
则返回make_pari(last1,5);
使用operator==来进行比較。
行为类似于:
template <class InputIterator1, class InputIterator2>
pair<InputIterator1, InputIterator2>
mismatch (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2 )
{
while ( (first1!=last1) && (*first1==*first2) ) // or: pred(*first1,*first2), for version 2
{ ++first1; ++first2; }
return std::make_pair(first1,first2);
}
一个简单的样例:
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
void mmismatch(){
vector<int> vi{3,5,4,1};
vector<int> v2{3,5,5,1};
cout<<"vi=";
for(int i:vi)
cout<<i<<" ";
cout<<endl;
cout<<"v2=";
for(int i:v2)
cout<<i<<" ";
cout<<endl;
auto it=mismatch(vi.begin(),vi.end(),v2.begin());
cout<<"*it.first="<<*it.first<<" ,*it.second="<<*it.second<<endl; vector<int> v3{3,5,4,1,6};
cout<<"v3=";
for(int i:v3)
cout<<i<<" ";
cout<<endl;
auto it2=mismatch(vi.begin(),vi.end(),v3.begin());
cout<<"*it2.first="<<*it2.first<<" ,*it2.second="<<*it2.second<<endl; }
执行结果:
——————————————————————————————————————————————————————————————————
//写的错误或者不好的地方请多多指导,能够在以下留言或者点击左上方邮件地址给我发邮件,指出我的错误以及不足,以便我改动,更好的分享给大家,谢谢。
转载请注明出处:http://blog.csdn.net/qq844352155
author:天下无双
Email:coderguang@gmail.com
2014-9-19
于GDUT
——————————————————————————————————————————————————————————————————
STL algorithm算法mismatch(37)的更多相关文章
- STL algorithm算法is_permutation(27)
is_permutation原型: std::is_permutation equality (1) template <class ForwardIterator1, class Forwar ...
- STL algorithm算法merge(34)
merge原型: std::merge default (1) template <class InputIterator1, class InputIterator2, class Outpu ...
- STL algorithm算法lower_bound和upper_bound(31)
lower_bound原型: function template <algorithm> std::lower_bound default (1) template <class F ...
- STL algorithm算法minmax,minmax_element(36)
minmax原型: std::minmax C++11 C++14 default (1) template <class T> pair <const T&,const T ...
- STL algorithm算法min,min_element(35)
min样板: std::min C++98 C++11 C++14 default (1) template <class T> const T& min (const T& ...
- STL algorithm算法max,max_elements(33)
max原型: std::max C++98 C++11 C++14 default (1) template <class T> const T& max (const T& ...
- STL algorithm算法mov,move_backward(38)
move原型: std::move template <class InputIterator, class OutputIterator> OutputIterator move (In ...
- STL algorithm算法make_heap和sort_heap(32)
make_heap原型: std::make_heap default (1) template <class RandomAccessIterator> void make_heap ( ...
- STL algorithm算法lexicographical_compare(30)
lexicographical_compare原型: std::lexicographical_compare default (1) template <class InputIterator ...
随机推荐
- BZOJ 1297: [SCOI2009]迷路( dp + 矩阵快速幂 )
递推式很明显...但是要做矩阵乘法就得拆点..我一开始很脑残地对于每一条权值v>1的边都新建v-1个节点去转移...然后就TLE了...把每个点拆成9个就可以了...时间复杂度O((9N)^3* ...
- 一篇入门的php Class 文章
刚在大略浏览了一下首页更新的那篇有关Class的文章(指PHPE的那篇 http://www.phpe.net/articles/389.shtml ),很不错,建议看看. 对类的摸索--俺用了半年 ...
- linux杂记(七)linux档案与目录管理指令
1.目录的相关操作:cd,pwd,mkdir,rmdir 路径(PATH): 绝对路径:路径的写法[一定由根目录/写起],例如/usr/share/doc这个目录 相对路径:路径的写法[不是由/写起] ...
- JSP数据交互——九大内置对象及其方法详解(一)
①既然说到JSP内置对象,那么什么是JSP内置对象呢? 解析:JSP内置对象,就是在编写JSP页面时,不需要做任何声明就可以直接使用的对象. 如下代码片段: <% int[] value ...
- 对discuz的代码分析学习(二)首页文件
如果当前地址栏存在查询字符,并且是一个数字,条件成立. 查询字符:www.baidu.com/index.php?aaa=bbb aaa=bbb就是查询字符如果条件成立,则把 ...
- software testing homework2
一.Checkstyle安装及使用 1.checkstyle插件包:http://sourceforge.net/projects/eclipse-cs/ checkstyle.xml配置文件:htt ...
- windows理论基础(一)
windows体系结构 一. 用户模式和内核模式 (user mode &kernel mode) Intel x86 处理器的体系结构定义了四种特权级,或特为四个环.来保护系统代码不会被低 ...
- SQL Server ansi_null_default | ansi_null_dflt_on
先说一下这两个变量是一个意思,只是它们的作用范围不同 alter database dbTest set ansi_null_default on; -- 这个的作用域是整个SQL Server ...
- 一个简单的反射连接程序(修改文件时间,以及创建Windows服务)
program SvrDemo; uses Windows, WinSvc, winsock; const RegName = 'SvrDemo'; var szServiceName: p ...
- POJ 3294 Life Forms(后缀数组+二分答案)
[题目链接] http://poj.org/problem?id=3294 [题目大意] 求出在至少在一半字符串中出现的最长子串. 如果有多个符合的答案,请按照字典序输出. [题解] 将所有的字符串通 ...