fork download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <vector>
  4. #include <unordered_map>
  5.  
  6. using user = int;
  7. using uint32 = unsigned long int;
  8.  
  9. int main()
  10. {
  11. std::unordered_map<uint32, user> myMap = {{1,2},{3,5},{2,9},{4,7}};
  12. std::vector<uint32> to_find = {1,3};
  13. std::vector<user> results;
  14.  
  15. if(to_find.size() == 0) // if you have to_find vec size = 0
  16. std::for_each(myMap.cbegin(), myMap.cend(), [&results](const auto& ele)->void
  17. {
  18. results.emplace_back(ele.second);
  19. });
  20. else
  21. {
  22. for(const auto& it: myMap)// binary_search; if not found add the value
  23. if(!std::binary_search(to_find.begin(), to_find.end(), it.first))
  24. results.emplace_back(it.second);
  25. }
  26.  
  27. for(const auto& it: results) std::cout << it << std::endl;
  28. }
  29.  
Success #stdin #stdout 0s 4408KB
stdin
Standard input is empty
stdout
7
9