Advertisement
Guest User

Untitled

a guest
Mar 18th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.65 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. //#include <conio.h>
  4. #include <vector>
  5. #include <string>
  6.  
  7. using std::cin;
  8. using std::cout;
  9. using std::vector;
  10. using std::string;
  11.  
  12. void WORRY(vector<bool>& vv, int index) {
  13.     vv[index] = false;
  14. }
  15.  
  16. void QUIET(vector<bool>& vv, int index) {
  17.     vv[index] = true;
  18. }
  19. void COME(vector<bool>& vv, int value) {
  20.     vv.resize(vv.size() + value, true);
  21.    
  22.     // if (value > 0) {
  23.         // for (int i(0); i < value; i++) {
  24.             // vv.push_back(true);
  25.         // }
  26.     // }
  27.     // else {
  28.         // for (int i(value); i < 0; i++) {
  29.             // if (vv.empty()) {
  30.                 // return;
  31.             // }
  32.             // vv.pop_back();
  33.         // }
  34.     // }
  35. }
  36. int WORRY_COUNT(vector<bool>& vv) {
  37.     int result = std::count(begin(vv), end(vv), false);
  38.     return result < 0 ? 0 : result;
  39. }
  40.  
  41. // std::ostream& operator<<(std::ostream& os, const vector<bool>& val) {
  42.     // for (const auto& item : val) {
  43.         // os << item << ", ";
  44.     // }
  45.     // return os;
  46. // }
  47.  
  48. // void TestCome() {
  49.     // vector<bool> vv;
  50.     // COME(vv, 5);
  51.     // COME(vv, -3);
  52.     // COME(vv, 7);
  53.     // COME(vv, -6);
  54.     // AssertEqual(vv, vector<bool>{ true, true, true }, "Come 1");
  55.     // AssertEqual(WORRY_COUNT(vv), 0, "Count 2");
  56.  
  57.     // COME(vv, -12);
  58.     // COME(vv, 7);
  59.     // COME(vv, -7);
  60.     // AssertEqual(vv, vector<bool>{}, "Come 2");
  61.     // AssertEqual(WORRY_COUNT(vv), 0, "Count 3");
  62. // }
  63. // void TestWorry() {
  64.     // vector<bool> vv(6, true);
  65.     // WORRY(vv, 1);
  66.     // WORRY(vv, 1);
  67.     // WORRY(vv, 4);
  68.     // WORRY(vv, 0);
  69.     // WORRY(vv, 6);
  70.     // WORRY(vv, 15);
  71.     // WORRY(vv, -5);
  72.     // AssertEqual(vv, vector<bool>{ false, true, true, false, true, false }, "Worry 1");
  73.     // AssertEqual(WORRY_COUNT(vv), 3, "Count 1");
  74. // }
  75. // void TestQuiet() {
  76.     // vector<bool> vv(6, false);
  77.     // QUIET(vv, 1);
  78.     // QUIET(vv, 1);
  79.     // QUIET(vv, 6);
  80.     // QUIET(vv, 3);
  81.     // QUIET(vv, 12);
  82.     // QUIET(vv, -1);
  83.     // QUIET(vv, 0);
  84.     // AssertEqual(vv, vector<bool>{true, false, true, false, false, true}, "Test Quiet 1");
  85.     // AssertEqual(WORRY_COUNT(vv), 3, "Count 4");
  86.  
  87. // }
  88.  
  89. // void TestAll() {
  90.     // UnitTest::TestRunner tr;
  91.     // tr.RunTest(TestCome, "Test come");
  92.     // tr.RunTest(TestWorry, "Test worry");
  93.     // tr.RunTest(TestQuiet, "Test quiet");
  94. // }
  95.  
  96. int main() {
  97.     //TestAll();
  98.     vector<bool> queue = {};
  99.     int n = 0;
  100.     cin >> n;
  101.     int temp = 0;
  102.     string opcode = "";
  103.     for (size_t i(0); i < n; i++) {
  104.         cin >> opcode;
  105.         if (opcode == "COME") {
  106.             cin >> temp;
  107.             COME(queue, temp);
  108.         }
  109.         else if (opcode == "QUET") {
  110.             cin >> temp;
  111.             QUIET(queue, temp);
  112.         }
  113.         else if (opcode == "WORRY") {
  114.             cin >> temp;
  115.             WORRY(queue, temp);
  116.         }
  117.         else if (opcode == "WORRY_COUNT") {
  118.             cout << WORRY_COUNT(queue) << std::endl;
  119.         }
  120.     }
  121.    
  122.     //_getch();
  123.     return 0;
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement