fork download
  1. #include <vector>
  2. #include <algorithm>
  3. #include <iostream>
  4.  
  5. int main() {
  6. int x[] = {1,2,3,4,5,6,7,8,9,10};
  7. int A[] = {3,4,5,6};
  8. int B[] = {5,6,7,8};
  9.  
  10. std::vector<int> array;
  11. std::copy_if(std::begin(x),std::end(x), std::back_inserter(array), [&A,&B](int n){
  12. return std::find(std::begin(A),std::end(A),n) != std::end(A) ||
  13. std::find(std::begin(B),std::end(B),n) != std::end(B);
  14. });
  15.  
  16. std::cout << "[ ";
  17. for(auto n: array) std::cout << n << ' ';
  18. std::cout << "]" << std::endl;
  19. return 0;
  20. }
  21.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
[ 3 4 5 6 7 8 ]