#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>
using namespace std;
int main( )
{
const int a[] = { 8, 7, 4, 9, 5, 2, 6, 2, 7,9, };
const int len = sizeof( a ) / sizeof( a[0] );
const int percentile_20 = static_cast<int>( 0.2 * len );
vector<int> v( a, a+len );
nth_element( v.begin(), v.begin()+percentile_20-1,v.end() );
copy( v.begin(), v.begin() + percentile_20,ostream_iterator<int>( cout, " " ) );
}
|