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