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 ...
随机推荐
- Qt QToolTip 控件背景的 QSS 设置方法(摘抄)
Qt/C++/CSS: QTooltip stylesheet background colour Hi there, I've recently come across a problem deve ...
- WPF中常用控件的属性
Source = new BitmapImage( new Uri( WangCaiConfig.GetCurrentDirectory() + imgStr, UriKind.RelativeOrA ...
- which 查看可执行文件的位置
我们经常在linux要查找某个文件,但不知道放在哪里了,可以使用下面的一些命令来搜索: which 查看可执行文件的位置. whereis 查看文件的位置. ...
- Mysql笔记之 -- replace()实现mysql 替换字符串
mysql 替换函数replace()实现mysql 替换字符串 mysql 替换字符串的实现方法: mysql中replace函数直接替换mysql数据库中某字段中的特定字符串,不再需要自己写函数 ...
- hdu 4033 Regular Polygon 计算几何 二分+余弦定理
题目链接 给一个n个顶点的正多边形, 给出多边形内部一个点到n个顶点的距离, 让你求出这个多边形的边长. 二分边长, 然后用余弦定理求出给出的相邻的两个边之间的夹角, 看所有的加起来是不是2Pi. # ...
- hdu 2471 简单DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2571 简单dp, dp[n][m] +=( dp[n-1][m],dp[n][m-1],d[i][k ...
- Paragraph Vector在Gensim和Tensorflow上的编写以及应用
上一期讨论了Tensorflow以及Gensim的Word2Vec模型的建设以及对比.这一期,我们来看一看Mikolov的另一个模型,即Paragraph Vector模型.目前,Mikolov以及B ...
- 电脑Win7如何取得文件管理所有权(提供各种GHOST版本的Windows)
电脑Windows7系统如何取得文件管理所有权?从 VISTA开始,微软对操作系统的安全性有了明显的提高,这样使得以前我们在XP下都可以打开或删除的文件(夹),无法在WIN7下进行操作.就算是在 Ad ...
- linux下解压iso文件
.iso文件的格式是iso9660,iso9660是cd上的一种文件系统, 也就是说是 是数据在cd上的组织形式: 它的一些限制是: 1.最多8级子目录(可以用RockRidge Extension增 ...
- BZOJ 2002 [Hnoi2010]Bounce 弹飞绵羊(动态树)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2002 [题目大意] 给出一片森林,操作允许更改一个节点的父亲,查询一个节点的深度. [ ...