Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. using namespace std;
  4. int main()
  5. {
  6.     int n, k;
  7.     cin >> n >> k;
  8.     string s;
  9.     cin >> s;
  10.     int c = 0;
  11.     if (k < 0)
  12.     {
  13.         c = -k;
  14.         k = 0;
  15.     }
  16.     for(int i = 0; i < n - 1; i++)
  17.     {
  18.         if (s[i] == 'A') k++;
  19.         else if (s[i] == 'C')
  20.         {
  21.             k--;
  22.             if (k < 0)
  23.             {
  24.                 c++;
  25.                 k = 0;
  26.             }
  27.         }
  28.     }
  29.     cout << c;
  30.     system("pause");
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement