Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- //#include <conio.h>
- #include <vector>
- #include <string>
- using std::cin;
- using std::cout;
- using std::vector;
- using std::string;
- void WORRY(vector<bool>& vv, int index) {
- vv[index] = false;
- }
- void QUIET(vector<bool>& vv, int index) {
- vv[index] = true;
- }
- void COME(vector<bool>& vv, int value) {
- vv.resize(vv.size() + value, true);
- // if (value > 0) {
- // for (int i(0); i < value; i++) {
- // vv.push_back(true);
- // }
- // }
- // else {
- // for (int i(value); i < 0; i++) {
- // if (vv.empty()) {
- // return;
- // }
- // vv.pop_back();
- // }
- // }
- }
- int WORRY_COUNT(vector<bool>& vv) {
- int result = std::count(begin(vv), end(vv), false);
- return result < 0 ? 0 : result;
- }
- // std::ostream& operator<<(std::ostream& os, const vector<bool>& val) {
- // for (const auto& item : val) {
- // os << item << ", ";
- // }
- // return os;
- // }
- // void TestCome() {
- // vector<bool> vv;
- // COME(vv, 5);
- // COME(vv, -3);
- // COME(vv, 7);
- // COME(vv, -6);
- // AssertEqual(vv, vector<bool>{ true, true, true }, "Come 1");
- // AssertEqual(WORRY_COUNT(vv), 0, "Count 2");
- // COME(vv, -12);
- // COME(vv, 7);
- // COME(vv, -7);
- // AssertEqual(vv, vector<bool>{}, "Come 2");
- // AssertEqual(WORRY_COUNT(vv), 0, "Count 3");
- // }
- // void TestWorry() {
- // vector<bool> vv(6, true);
- // WORRY(vv, 1);
- // WORRY(vv, 1);
- // WORRY(vv, 4);
- // WORRY(vv, 0);
- // WORRY(vv, 6);
- // WORRY(vv, 15);
- // WORRY(vv, -5);
- // AssertEqual(vv, vector<bool>{ false, true, true, false, true, false }, "Worry 1");
- // AssertEqual(WORRY_COUNT(vv), 3, "Count 1");
- // }
- // void TestQuiet() {
- // vector<bool> vv(6, false);
- // QUIET(vv, 1);
- // QUIET(vv, 1);
- // QUIET(vv, 6);
- // QUIET(vv, 3);
- // QUIET(vv, 12);
- // QUIET(vv, -1);
- // QUIET(vv, 0);
- // AssertEqual(vv, vector<bool>{true, false, true, false, false, true}, "Test Quiet 1");
- // AssertEqual(WORRY_COUNT(vv), 3, "Count 4");
- // }
- // void TestAll() {
- // UnitTest::TestRunner tr;
- // tr.RunTest(TestCome, "Test come");
- // tr.RunTest(TestWorry, "Test worry");
- // tr.RunTest(TestQuiet, "Test quiet");
- // }
- int main() {
- //TestAll();
- vector<bool> queue = {};
- int n = 0;
- cin >> n;
- int temp = 0;
- string opcode = "";
- for (size_t i(0); i < n; i++) {
- cin >> opcode;
- if (opcode == "COME") {
- cin >> temp;
- COME(queue, temp);
- }
- else if (opcode == "QUET") {
- cin >> temp;
- QUIET(queue, temp);
- }
- else if (opcode == "WORRY") {
- cin >> temp;
- WORRY(queue, temp);
- }
- else if (opcode == "WORRY_COUNT") {
- cout << WORRY_COUNT(queue) << std::endl;
- }
- }
- //_getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement