各种算法,近日得闲,敲了一下:看算法名称,也大概能猜出这个算法是做什么的,因此,看一下例子就算了,不解释了;
#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};
vector<int>v(a,a+10);
vector<int>vv(a+3,a+8);
vector<int>::iterator it=find_first_of(v.begin(),v.end(),vv.begin(),vv.end());
//cout<<distance(v.begin(),it)<<endl;
//cout<<*it<<endl;
while(it!=v.end()){
cout<<"found"<<distance(v.begin(),it)<<endl;
++it;
it=find_first_of(it,v.end(),vv.begin(),vv.end());
}
system("pause");
return 0;
}
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
bool chenger(int a,int b){
return a*2==b;
}
using namespace std;
int main(){
int a[]={1,2,3,4,5,6,7,8,9,10};
vector<int>v(a,a+10);
vector<int>vv(a+3,a+8);
for(vector<int>::iterator ite=vv.begin();ite!=vv.end();++ite){
cout<<*ite<<" ";
}
cout<<endl;
vector<int>::iterator it=find_first_of(v.begin(),v.end(),vv.begin(),vv.end(),chenger);
cout<<*it<<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};
vector<int>v(a,a+10);
vector<int>vv(a+3,a+8);
vector<int>::iterator first;
vector<int>::reverse_iterator last;
first=find_first_of(v.begin(),v.end(),vv.begin(),vv.end());
last=find_first_of(v.rbegin(),v.rend(),vv.begin(),vv.end());
cout<<"the first location: "<<distance(v.begin(),first)<<endl;
cout<<"the last locatioin: "<<distance(v.begin(),last.base())<<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,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;
}
#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[]={1,2,3,5,6,7,8,9,10,11};
vector<int>v(a,a+10);
vector<int>vv(b,b+10);
pair<vector<int>::iterator,vector<int>::iterator>pa=mismatch(v.begin(),v.end(),vv.begin());
if(pa.first!=v.end()&&pa.second!=vv.end()){
cout<<"第一个在v中不匹配的是"<<*(pa.first)<<endl;
cout<<"第一个在vv中不匹配的是"<<*(pa.second)<<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[]={1,2,3,4,5,6,7,8,9,10};
vector<int>v(a,a+10);
vector<int>vv(b,b+10);
if(lexicographical_compare(v.begin(),v.end(),vv.begin(),vv.end())){
cout<<"符合字典次序"<<endl;
}else{
cout<<"不合符字典次序"<<endl;
}
cout<<endl;
system("pause");
return 0;
}
分享到:
相关推荐
adjacent_find all_of any_of binary_search clamp copy copy_backward copy_if copy_n count count_if equal equal_range fill fill_n find find_first_of find_if find_if_not for_each for_...
ForwardIterator adjacent_find (ForwardIterator first, ForwardIterator last) { if (first == last) return last; ForwardIterator next = first; while (++next != last) { if (*first == *next) return ...
UMLS的语义类型和语义... adjacent_to surrounds traverses functionally_related_to affects manages treats disrupts complicates interacts_with prevents brings_about produces causes
The implementation uses adjacency list representation of graphs. List container is used to store lists of adjacent nodes and queue of nodes needed for Breath First Search traversal.
34.19 lexicographical_compare 34.20 lower_bound 34.21 make_heap 34.22 max 34.23 max_element 34.24 merge 34.25 min 34.26 min_element 34.27 mismatch 34.28 next_permutation 34.29 nth_element 34.30 ...
23.27 字典比较lexicographical_compare 405 23.28 下一排列组合next_permutation 406 23.29 上一排列组合prev_permutation 409 23.30 本章小结 411 第24章 数值算法 412 24.1 递增赋值iota 412 24.2 ...
23.27 字典比较lexicographical_compare 405 23.28 下一排列组合next_permutation 406 23.29 上一排列组合prev_permutation 409 23.30 本章小结 411 第24章 数值算法 412 24.1 递增赋值iota 412 24.2 ...
23.27 字典比较lexicographical_compare 405 23.28 下一排列组合next_permutation 406 23.29 上一排列组合prev_permutation 409 23.30 本章小结 411 第24章 数值算法 412 24.1 递增赋值iota 412 24.2 ...
lexicographical_compare 310 max, min 312 mismatch 313 swap 314 6.4.3 copy,强化效率无所不用其极 314 6.4.4 copy_backward 326 6.5 set 相关算法(应用于有序区间) 328 6.5.1 set_union 331 6.5.2 set...
lexicographical_compare 310 max, min 312 mismatch 313 swap 314 6.4.3 copy,强化效率无所不用其极 314 6.4.4 copy_backward 326 6.5 Set 相关算法(应用于有序区间) 328 6.5.1 set_union 331 6.5.2 set...
一、非修改性序列操作(12个) 循环 对序列中的每个元素执行某操作 for_each() 查找 在序列中找出某个值的第一次出现的...在序列中找出相邻的一对值 adjacent_find() 计数 在序列中统计某个值出现的次数 count()
How far does the power of the adjacent vertex methods extend in solvingnon-linear programming problems? This question here gets a partial answebeing restricted to variables and objective functions ...
主要包含kAS的文档和PPT,以及相关的文献。之前导师让做kAS报告时收集的资料,请需要的下载。
PKU_3786Adjacent Bit Counts
First, we compare the advantages and disadvantages of three typical sensor plans and introduce a general autopilot for a vehicle. Second, we introduce a software architecture for an autonomous ...
详细介绍的射频领域的临近信道抑制问题, 射频基础知识概念的解释。 希望对大家有用,帮助大家成长为射频工程师
In this paper we present a statistical change ... In particular, the projection of the pattern onto the subspace is computed by an O(N) iterative procedure known as Pool Adjacent Violators algorithm.
If there is no clustered index, there is a sysindexes row for the table with an indid value of 0, and that row will keep track of the address of the first IAM for the table. The IAM is a giant bitmap...
用于等渗回归的Pair Adjacent Violators算法的实现。用Kotlin编写,但可用于 Java 或任何其他 JVM 语言。 请注意,此算法也称为“池相邻违规者”。 什么是“等渗回归”,我为什么要关心? 假设您有两个变量x和y,...
MESSAGE Modifies the faces of a body by the use of various methods. HINT This command is superseded by Synchronous Modeling commands. To run this legacy command, set UGII_DMX_NX502=1. HELP DSN_face...