logo CodeStepByStep logo

collectionMystery5

Language/Type: C++ collections Map
Author: Marty Stepp (on 2016/06/16)

Write the output produced by the following function when passed each of the following maps:

void collectionMystery5(Map<string, int>& m1, Map<int, string>& m2) {
    Map<string, string> result;
    for (string s : m1) {
        if (m2.containsKey(m1[s])) {
            result[s] = m2[m1[s]];
        }
    }
    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?

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.

© Marty Stepp, all rights reserved.