La Bag de un jueguito guarda en items cuántos tiene de cada cosa. Escribe use(item): si no tiene ninguno, devuelve false; si no, quita uno y devuelve true, y cuando llegue a 0, bórralo de la mochila con erase.
bag_after({"potion", "potion", "key"}, {"potion"})→{'key': 1, 'potion': 1}bag_after({"key"}, {"key"})→{}map<string, int> bag_after(const vector<string> &picks, const vector<string> &uses)#include <map>
#include <string>
#include <vector>
using namespace std;
class Bag {
public:
map<string, int> items;
void pick(const string &item) {
items[item]++;
}
bool use(const string &item) {
// tu código aquí: gasta un objeto
return false;
}
};
map<string, int> bag_after(const vector<string> &picks, const vector<string> &uses) {
Bag b;
for (const string &p : picks) {
b.pick(p);
}
for (const string &u : uses) {
b.use(u);
}
return b.items;
}
Ejecutar prueba los ejemplos. Cuando salgan bien, Enviar.