STL algorithm算法mismatch(37)
来源:互联网 发布:打谱软件overture4.0 编辑:程序博客网 时间:2024/04/27 18:38
mismatch原型:
std::mismatch
template <class InputIterator1, class InputIterator2> pair<InputIterator1, InputIterator2> mismatch (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
template <class InputIterator1, class InputIterator2, class BinaryPredicate> pair<InputIterator1, InputIterator2> mismatch (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate pred);
例如:
序列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
——————————————————————————————————————————————————————————————————
0 0
- STL algorithm算法mismatch(37)
- STL algorithm算法集合
- 【STL】algorithm算法介绍
- C++ STL算法系列5---equal() , mismatch()
- C++ STL算法系列5---equal() , mismatch()
- C++ STL算法系列5---equal() , mismatch()
- STL algorithm算法binary_search(5)
- STL algorithm算法copy(6)
- STL algorithm算法copy_backward(7)
- STL algorithm算法copy_if(8)
- STL algorithm算法copy_n(9)
- STL algorithm算法count(10)
- STL algorithm算法count_if(11)
- STL algorithm算法equal(12)
- STL algorithm算法equal_range(13)
- STL algorithm算法fill(14)
- STL algorithm算法find_end(17)
- STL algorithm算法find_first_of(18)
- 乒乓球比赛
- the request was rejected
- byte[] 数组越界,System.arraycopy()方法
- Codeforces 467D Fedor and Essay bfs
- 在android上运行ubuntu13.10
- STL algorithm算法mismatch(37)
- jquery学习笔记之选择器
- js 把非数数字不允许输入
- ksum 问题
- 安防
- Struts2初认识(1)
- Flex 页面空白或Error #2032
- java中的控制台输入
- Android的bootloader