Vor dem Campingausflug gehst du die Liste durch: packed sagt, ob jedes Ding im Rucksack ist (true heißt gepackt). Schreib still_to_pack(packed): Steck die Dinge, die noch nicht gepackt sind, in alphabetischer Reihenfolge in todo. Ist alles gepackt, gib es leer zurück.
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) {
// dein Code hier: noch nicht gepackt kommt in todo
}
return todo;
}
Ausführen testet die Beispiele. Wenn sie passen, drück auf Abgeben.