Kodewick
开始学 →
基础←→0 / 60

露营清单

#054基础mapvector约 5 分钟

去露营前对一遍清单,packed 记着每样东西装好了没有(true 是装好了)。写 still_to_pack(packed):把还没装的放进 todo,按字母顺序。都装好了就返回空的。

示例
still_to_pack({{"tent", true}, {"torch", false}, {"map", false}})→['map', 'torch']
still_to_pack({})→[]
函数vector<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) {
        // 在这里写:还没装就放进 todo
    }
    return todo;
}
Ctrl + Enter 也能运行
结果

写好了先点「运行」试试示例,没问题再点「提交」。