A little game starts with 3 lives. Each event: "hit" loses one, "heart" gains one, anything else changes nothing. Once lives reach 0 the game is over and later events don't count, so return 0. Write lives_left(events) to return how many lives are left.
lives_left({"hit", "heart", "hit"})→2lives_left({"hit", "hit", "hit", "heart"})→0int lives_left(const vector<string> &events)#include <string>
#include <vector>
using namespace std;
int lives_left(const vector<string> &events) {
int lives = 3;
for (const string &e : events) {
// your code here: add or take a life for e, and return 0 once it reaches 0
}
return lives;
}
Run tries the examples. When they look right, Submit.