プログラミング道場 ACM/ICPC

列Aの中に列Bの要素が全て含まれているか

最終更新:

kit

- view
だれでも歓迎! 編集
/*
	template<class _InIt1, class _InIt2>
	bool includes(
		_InIt1 _First1, _InIt1 _Last1,
		_InIt2 _First2, _InIt2 _Last2)
		
	template<class _InIt1, class _InIt2, class _Pr>
	bool includes(
		_InIt1 _First1, _InIt1 _Last1,
		_InIt2 _First2, _InIt2 _Last2,
		_Pr _Pred )
*/

#include <algorithm>
#include <iostream>
#include <functional>

using namespace std;

int main()
{
	//対象となる列はソートされていなければいけない
	int a[] = {1,4,9};
	int b[] = {1,9};
	int c[] = {5};

	//true
	cout << ( includes( a,a+3, b,b+2 ) ? "true":"false" ) << endl;

	//false
	cout << ( includes( a,a+3, c,c+1 ) ? "true":"false" ) << endl;

	sort( a,a+3, greater<int>() );
	sort( b,b+2, greater<int>() );
	sort( c,c+1, greater<int>() );

	//true
	cout << ( includes( a,a+3, b,b+2, greater<int>() ) ? "true" : "false" ) << endl;

	return 0;
}
ウィキ募集バナー