代码改变世界

mismatch和lexicographical_compare

2012-07-29 15:48  java线程例子  阅读(219)  评论(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()),jianyi){
		cout<<"符合字典次序"<<endl;
	}else{
		cout<<"不合符字典次序"<<endl;
	}
	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[]={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;
}