Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm> //для count
- using namespace std;
- int main() {
- int q;
- cin >> q;
- vector<bool>queue;
- for (int i = 0; i < q; ++i) {
- string operation_code;
- cin >> operation_code;
- if (operation_code == "WORRY"s) {
- int index;
- cin >> index;
- queue[index] = true;
- }
- else if (operation_code == "HAPPY"s) {
- int index;
- cin >> index;
- queue[index] = false;
- }
- else if (operation_code == "COME"s) {
- int count;
- cin >> count;
- queue.resize(queue.size()+count, false);
- }
- else if (operation_code == "LAST_WORRY"s) {
- if (!queue.empty()) {
- if (queue.back() == true) {
- cout << "worry" << endl;
- }
- if (queue.back() == false) {
- cout << "happy" << endl;
- }
- }
- }
- else if (operation_code == "WORRY_COUNT") {
- int count_ = count(queue.begin(), queue.end(), true); //функция count для подсчета необходимых значений в векторе
- //https://en.cppreference.com/w/cpp/algorithm/count
- cout << count_ << endl;
- }
- }
- }
Advertisement
Advertisement