logo CodeStepByStep logo

collectionMystery2

Language/Type: C++ collections map set STL

Write the output produced by the following function when passed each of the following maps. Assume that a set displays itself in {10, 20, 30} format.

void collectionMystery2(map<string, string>& m) {
    set<string> s;
    for (auto kv : m) {
        if (kv.first != kv.second) {
            s.insert(kv.second);
        } else {
            s.erase(kv.second);
        }
    }
    cout << s << endl;
}
{"cast":"plaster", "house":"brick", "sheep":"wool", "wool":"wool"}
{"ball":"blue", "corn":"yellow", "emerald":"green", "grass":"green", "winkie":"yellow"}
{"apple":"peach", "corn":"apple", "peach":"peach", "pie":"fruit", "potato":"peach"}
{"cat":"cat", "corgi":"dog", "emu":"animal", "lab":"lair", "lair":"lair", "nyan":"cat"}

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.