find_end,find_first_of
2012-07-29 15:44 java线程例子 阅读(313) 评论(0) 编辑 收藏 举报直接代码:
#include<iostream> #include<string> #include<vector> #include<algorithm> using namespace std; int main(){ int a[]={1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10}; vector<int>v(a,a+20); vector<int>vv(a+3,a+8); vector<int>::iterator end=v.end(); vector<int>::iterator it; it=find_end(v.begin(),v.end(),vv.begin(),vv.end()); while(it!=end){ cout<<"found "<<distance(v.begin(),it)<<endl; end=it; it=find_end(v.begin(),end,vv.begin(),vv.end()); } 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 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; }