fork download
  1. #include <iostream>
  2. #include <set>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using std::cout;
  7. using std::endl;
  8.  
  9. using std::set;
  10. using std::vector;
  11. using std::remove_copy_if;
  12.  
  13. int main(){
  14. vector<int> a = {1, 2, 3, 4, 6, 5, 2, 3, 4, 1, 2, 5, 1, 3, 6, 5};
  15. vector<int> b(a.size());
  16. set<int> s;
  17.  
  18. remove_copy_if(a.begin(), a.end(), b.begin(), [&](int v){
  19. if(s.find(v) != s.end()){
  20. return true;
  21. }else{
  22. s.insert(v);
  23. return false;
  24. }
  25. });
  26. b.resize(s.size());
  27.  
  28. for_each(b.begin(), b.end(), [](int v){
  29. cout << v << ' ';
  30. });
  31.  
  32. cout << endl;
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
1 2 3 4 6 5