Kodewick
Start learning →
Basic←→0 / 60

Camping checklist

#054BasicMapsvector5 min

Before the camping trip you check the list: packed says whether each thing is in the bag (true means packed). Write still_to_pack(packed): put the things not packed yet into todo, in alphabetical order. If everything is packed, return it empty.

Examples
still_to_pack({{"tent", true}, {"torch", false}, {"map", false}})→['map', 'torch']
still_to_pack({})→[]
The functionvector<string> still_to_pack(const map<string, bool> &packed)
main.cpp
#include <map>
#include <string>
#include <vector>
using namespace std;

vector<string> still_to_pack(const map<string, bool> &packed) {
    vector<string> todo;
    for (const auto &p : packed) {
        // your code here: not packed yet goes into todo
    }
    return todo;
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.