去露營前對一遍清單,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;
}
寫好了先點「執行」試試示例,沒問題再點「提交」。