logo CodeStepByStep logo

collectionMystery5

Language/Type: C++ collections map STL

Write the output produced by the following function when passed each of the following maps. Assume that a map displays in {key:value, key:value, ..., key:value} format.

void collectionMystery5(map<string, int>& m1, map<int, string>& m2) {
    map<string, string> result;
    for (auto kv : m1) {
        if (m2.find(kv.second) != m2.end()) {
            result[kv.first] = m2[kv.second];
        }
    }
    cout << result << endl;
}
m1: {"bar":1, "cat":2, "foo":3, "mum":4}, m2: {1:"earth", 2:"wind", 3:"air", 4:"fire"}
m1: {"five":105, "four":104, "one":101, "six":106, "three":103, "two":102}, m2: {99:"uno", 101:"dos", 103:"tres", 105:"cuatro"}
m1: {"a":42, "b":9, "c":7, "d":15, "e":11, "f":24, "g":7}, m2: {1:"four", 3:"score", 5:"and", 7:"seven", 9:"years", 11:"ago"}

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.