Ошибка вот здесь:
int counter;
Инициализируйте её:
int counter = 0;
.
#include <iostream>
#include <string>
#include <vector>
void change_status(int i, std::vector<bool>& people) {
if (i > people.size()) {
people.resize(i + 1);
}
if (i > 0) {
people[i] = true;
}
}
void come(int k, std::vector<bool>& people) {
people.resize(people.size() + k + 1);
}
void worry_count(const std::vector<std::string>& commands, const std::vector<int>& values, std::vector<bool>& people) {
int counter = 0;
for (bool person : people) {
if (person) {
++counter;
}
}
std::cout << counter << std::endl;
}
int main(void) {
std::vector<std::string> commands = {"COME", "WORRY", "WORRY", "COME", "WORRY_COUNT", "COME", "WORRY", "WORRY_COUNT"};
std::vector<int> values = {5, 1, 4, -2, 0, 3, 3, 0};
std::vector<bool> people; // true - беспокоящийся человек, false - спокойный
int i = 0;
for (std::string command : commands) {
if (command == "WORRY" || command == "QUIET") {
change_status(i, people);
} else if (command == "COME") {
come(i, people);
} else {
worry_count(commands, values, people);
}
++i;
}
return 0;
}