fork download
  1. #include <iostream>
  2. #include <map>
  3. using namespace std;
  4.  
  5. int main() {
  6. map<int, int> foo = {{1, 100}, {2, 200}, {4, 400}};
  7. map<char, int> bar = {{'1', 200}, {'3', 300}, {'5', 500}};
  8.  
  9. for(auto i = foo.begin(); i != foo.end(); ++i) {
  10. if(bar.end() == bar.find(static_cast<decltype(bar)::key_type>(i->first) + '0')){
  11. foo.erase(i);
  12. }
  13. }
  14.  
  15. for(auto i = bar.begin(); i != bar.end(); ++i) {
  16. const decltype(foo)::key_type key = i->first - '0';
  17.  
  18. if(foo.end() == foo.find(key) || foo[key] != i->second) {
  19. foo[key] = i->second;
  20. }
  21. }
  22.  
  23. for(const auto i : foo){
  24. cout << i.first + 10 << ": " << i.second << endl;
  25. }
  26.  
  27. return 0;
  28. }
Success #stdin #stdout 0s 3464KB
stdin
Standard input is empty
stdout
11: 200
13: 300
15: 500