fork download
  1. #include <iostream>
  2. #include <map>
  3. using namespace std;
  4.  
  5. int main() {
  6. map<int,int> col1 { {4,1},{6,2},{8,4}, {10,6}};
  7. map<int,int> col2 { {5,1},{9,2},{4,4},{10,6}};
  8. map<int,pair<int,int>> common ;
  9.  
  10. for (auto& x: col1) {
  11. auto y= col2.find(x.first);
  12. if (y!=col2.end())
  13. common[x.first]=make_pair(x.second,y->second);
  14. }
  15. cout<<"Result:"<<endl;
  16. for (auto& x:common )
  17. cout << x.first << "<-" << x.second.first << " in col1 and " <<x.second.second << " in col2"<<endl;
  18. return 0;
  19. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Result:
4<-1 in col1 and 4 in col2
10<-6 in col1 and 6 in col2