小さなゲームはライフ 3 から始まります。出来事ごとに、"hit" なら 1 減り、"heart" なら 1 増え、それ以外は変わりません。ライフが 0 になったらゲームオーバーで、そのあとの出来事は数えないので 0 を返します。残りのライフを返す lives_left(events) を書きましょう。
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) {
// ここにコードを書く:e に合わせてライフを増減し、0 になったら 0 を返す
}
return lives;
}
実行すると例で試せます。よさそうなら提出しましょう。