1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
#include <iostream>
#include <algorithm>
#include <iterator>
int main()
{
int a[] = { 1, 7, 3, 3, 1, 6, 5, 7, 4, 6 };
int b[sizeof( a ) / sizeof( *a )];
std::copy( std::begin( a ), std::end( a ), std::ostream_iterator<int>( std::cout, " " ) );
std::cout << std::endl;
std::copy( std::begin( a ), std::end( a ), std::begin( b ) );
std::sort( std::begin( b ), std::end( b ) );
auto last = std::unique( std::begin( b ), std::end( b ) );
std::copy( std::begin( b ), last, std::ostream_iterator<int>( std::cout, " " ) );
std::cout << std::endl;
std::cout << "The new array contains "
<< std::distance( std::begin( b ), last )
<< " unique elements." << std::endl;
}
|