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

列の中の連続している要素を消す

最終更新:

kit

- view
だれでも歓迎! 編集
/*
	template<class _FwdIt>
	_FwdIt unique(_FwdIt _First, _FwdIt _Last)

	template<class _FwdIt, class _Pr> inline
	_FwdIt unique(_FwdIt _First, _FwdIt _Last, _Pr _Pred)
*/

#include <algorithm>
#include <iostream>

using namespace std;

int main()
{
	int a[10];

	//ソートされている必要は無い
	//ソートされていた場合は重複する全ての要素が消える
	for( int i = 1, j = 0; i <= 4; ++i )
		for( int k = 0; k < i; ++k )
			a[j++] = i;

	// 1,2,2,3,3,3,4,4,4,4,
	copy( a,a+10, ostream_iterator<int>(cout,",") );
	cout << endl;

	// 1,2,3,4,
 	copy( a,unique(a,a+10), ostream_iterator<int>(cout,",") );
 	cout << endl;	

	return 0;
}

タグ:

+ タグ編集
  • タグ:

このサイトはreCAPTCHAによって保護されており、Googleの プライバシーポリシー利用規約 が適用されます。

目安箱バナー