去露营前对一遍清单,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)#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;
}
写好了先点「运行」试试示例,没问题再点「提交」。