fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <unordered_set>
  4. #include <algorithm>
  5.  
  6. void removeAll_unordered( std::vector<int> &a, const std::vector<int> &b )
  7. {
  8. auto end = std::remove_if( a.begin(), a.end(),
  9. [set = std::unordered_set<int>( b.begin(), b.end() )]( int i ) {
  10. return set.count( i );
  11. } );
  12. a.erase( end, a.end() );
  13. }
  14.  
  15. int main() {
  16. std::vector<int> a = { 5, 7, 14, 0, 6, 2, 9, 11, 3 };
  17. std::vector<int> b = { 6, 4, 3, 10, 9, 15, 7 };
  18. removeAll_unordered( a, b );
  19. for( auto i : a ) std::cout << i << " ";
  20. std::cout << std::endl;
  21. return 0;
  22. }
Success #stdin #stdout 0s 4548KB
stdin
Standard input is empty
stdout
5 14 0 2 11