Advertisement
MagicWinnie

Untitled

Nov 28th, 2021 (edited)
685
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int n, q;
  10.     string s;
  11.     cin >> n >> s >> q;
  12.     // map<char, int> count;
  13.     vector<int> positions;
  14.     int pos = 0, count = 0;
  15.     while ((pos = s.find("PSU", pos)) != string::npos) {
  16.         ++count;
  17.         positions.push_back(pos);
  18.         pos += 3;
  19.     }
  20.     cout << count << endl;
  21.     char ch;
  22.     for (int i = 0; i < q; i++)
  23.     {
  24.         cin >> pos >> ch;
  25.         pos--;
  26.         bool a = false, b = false, c = false;
  27.         if (pos - 2 >= 0)
  28.         {
  29.             if (s.substr(pos - 2, 3) == "PSU")
  30.                 a = true;
  31.             // cout << 0 << s.substr(pos - 2, 3) << endl;
  32.         }
  33.         if (pos - 1 >= 0)
  34.         {
  35.             if (s.substr(pos - 1, 3) == "PSU")
  36.                 b = true;
  37.             // cout << 1 << s.substr(pos - 1, 3) << endl;
  38.         }
  39.         if (s.substr(pos, 3) == "PSU")
  40.             c = true;
  41.         // cout << 2 << s.substr(pos, 3) << endl;
  42.         // cout << "CHANGE" << endl;
  43.         s[pos] = ch;
  44.         if (pos - 2 >= 0)
  45.         {
  46.             // cout << s.substr(pos - 2, 3) << endl;
  47.             if (s.substr(pos - 2, 3) == "PSU" && !a)
  48.                 count++;
  49.             else if (s.substr(pos - 2, 3) != "PSU" && a)
  50.                 count--;
  51.         }
  52.         if (pos - 1 >= 0)
  53.         {
  54.             // cout << s.substr(pos - 1, 3) << endl;
  55.             if (s.substr(pos - 1, 3) == "PSU" && !b)
  56.                 count++;
  57.             else if (s.substr(pos - 1, 3) != "PSU" && b)
  58.                 count--;
  59.         }
  60.         // cout << 2 << s.substr(pos, 3) << endl;
  61.         if (s.substr(pos, 3) == "PSU" && !c)
  62.             count++;
  63.         else if (s.substr(pos, 3) != "PSU" && c)
  64.             count--;    
  65.         // cout << s << endl;
  66.         cout << count << endl;
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement