`
java-mans
  • 浏览: 11438832 次
文章分类
社区版块
存档分类
最新评论

adjacent_find,equal

 
阅读更多

代码如下:

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>

using namespace std;
int main(){
	int a[]={1,2,3,4,5,6,6,8,9,10};
	vector<int>v(a,a+10);
	vector<int>vv(a+3,a+8);
	
	vector<int>::iterator it;
	it=adjacent_find(v.begin(),v.end());//寻找两个连续且相等的元素,在这一点上,有一点像search_n(v.begin(),v.end(),2,X);
	if(it!=v.end()){
		cout<<"found the two number equals"<<endl;
		cout<<*it<<endl;
	}else{
		cout<<"none"<<endl;
	}
	system("pause");
	return 0;
}
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
bool liangbei(int a,int b){
	return 2*a==b;
}
using namespace std;
int main(){
	int a[]={1,2,3,4,5,6,6,8,9,10};
	vector<int>v(a,a+10);
	vector<int>vv(a+3,a+8);
	
	vector<int>::iterator it;
	it=adjacent_find(v.begin(),v.end(),liangbei);
	if(it!=v.end()){
		cout<<"找到了第一个符合条件的两个连续的元素,其中后一个是前一个元素的两倍"<<endl;
		cout<<*it<<" "<<*(it+1)<<endl;
	}else{
		cout<<"没有找到"<<endl;
	}
	system("pause");
	return 0;
}
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
	int a[]={1,2,3,4,5,6,7,8,9,10};
	int b[]={2,3,4,5,6,7,8,9,10,11};
	vector<int>v(a,a+10);
	vector<int>vv(b,b+10);
	vector<int>vvv(a,a+10);
	if(equal(v.begin(),v.end(),vv.begin())){
		cout<<"v=vv"<<endl;
	}else{
		cout<<"v!=vv"<<endl;
	}
	if(equal(v.begin(),v.end(),vvv.begin())){
		cout<<"v=vvv"<<endl;
	}else{
		cout<<"v!=vvv"<<endl;
	}
	system("pause");
	return 0;
}
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;
bool jianyi(int a,int b){
	return a==b-1;
}
int main(){
	int a[]={1,2,3,4,5,6,7,8,9,10};
	int b[]={2,3,4,5,6,7,8,9,10,11};
	vector<int>v(a,a+10);
	vector<int>vv(b,b+10);
	vector<int>vvv(a,a+10);
	
	if(equal(v.begin(),v.end(),vv.begin(),jianyi)){
		cout<<"vv中的每个元素减去一 与V的元素相等"<<endl;
	}else{
		cout<<"还是不相等"<<endl;
	}
	system("pause");
	return 0;
}


分享到:
评论

相关推荐

    30-seconds-of-cpp:30秒的C ++(C ++中的STL)。 在此处阅读有关30C ++的更多信息:backhand_index_pointing_right:

    30秒的C ++ 30秒的C ++标准模板库 可以在30秒或更短时间内学会的C ++ STL... equal_range fill fill_n find find_first_of find_if find_if_not for_each for_each_n generate includes iota is_heap is

    SGI-STL 源码以及 word 注解版

    ForwardIterator adjacent_find (ForwardIterator first, ForwardIterator last) { if (first == last) return last; ForwardIterator next = first; while (++next != last) { if (*first == *next) return ...

    STL源码剖析.pdg

    equal_to, not_equal_to, greater, greater_equal, less, less_equal 7.5 逻辑运算类(logical)仿函数 422 logical_and, logical_or, logical_not 7.6 证同(identity)、选择(select)、投射(project) 423 ...

    STL 源码剖析(侯捷先生译著)

    equal_to, not_equal_to, greater, greater_equal, less, less_equal 7.5 逻辑运算类(Logical)仿函数 422 logical_and, logical_or, logical_not 7.6 证同(identity)、选择(select)、投射(project) 423 ...

    C++ STL 开发技术导引(第6章)

    23.16 等价区间equal_range 390 23.17 折半搜索binary_search 392 23.18 子集合includes 393 23.19 集合求并set_union 394 23.20 集合求交set_ intersection 396 23.21 集合求差set_difference 398 ...

    C++ STL开发技术导引(第5章)

    23.16 等价区间equal_range 390 23.17 折半搜索binary_search 392 23.18 子集合includes 393 23.19 集合求并set_union 394 23.20 集合求交set_ intersection 396 23.21 集合求差set_difference 398 ...

    C++ STL开发技术导引(第3章)

    23.16 等价区间equal_range 390 23.17 折半搜索binary_search 392 23.18 子集合includes 393 23.19 集合求并set_union 394 23.20 集合求交set_ intersection 396 23.21 集合求差set_difference 398 ...

    -C++参考大全(第四版) (2010 年度畅销榜

    34.8 equal_range 34.9 flll和fill_n 34.10 find 34.11 find_end 34.12 find_first_of 34.13 find_if 34.14 for_each 34.15 generate和generate_n 34.16 includes 34.17 inplace_merge 34.18 iter_swap 34.19 ...

    微软内部资料-SQL性能优化5

    In a nonclustered index, the leaf level contains each index key, plus a bookmark that tells SQL Server where to find the data row corresponding to the key in the index. A bookmark can take one of two ...

    convmv-1.15.tar.gz

    By the way: The superscript dot of the letter i was added in the Middle Ages to distinguish the letter (in manuscripts) from adjacent vertical strokes in such letters as u, m, and n. J is a variant ...

    计算机网络第六版答案

    27. Creation of a botnet requires an attacker to find vulnerability in some application or system (e.g. exploiting the buffer overflow vulnerability that might exist in an application). After finding ...

Global site tag (gtag.js) - Google Analytics