Guest User

Untitled

a guest
May 21st, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <vector>
  4.  
  5. int main(int argc, const char * argv[]) {
  6.  
  7. std::vector<int> v1 = {1, 3, 5, 7, 2, 4, 6, 8, 9, 11, 13, 10, 20, 8, 15, 14, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  8. unsigned k = 3;
  9.  
  10. auto it = std::next(v1.begin(), v1.size() - k);
  11. std::nth_element(v1.begin(), it, v1.end());
  12. std::copy(it, v1.end(), std::ostream_iterator<int>{std::cout, " "});
  13. std::cout << std::endl;
  14.  
  15.  
  16. return 0;
  17. }
Add Comment
Please, Sign In to add comment