Advertisement
Saleh127

Cf 1428C

Oct 19th, 2020
60
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);cout.tie(0);
  9.  
  10. test
  11. {
  12.  
  13. string a;
  14. ll c,d,e,f,i,j,k=0,l=0;
  15.  
  16. cin>>a;
  17. c=a.size();
  18.  
  19. stack<char >x;
  20. for(i=0;i<c;i++)
  21. {
  22. if(x.empty())
  23. {
  24. x.push(a[i]);
  25. }
  26. else if(a[i]=='B')
  27. {
  28. if(x.top()=='A')
  29. {
  30. x.pop();
  31. }
  32. else if(x.top()=='B')
  33. {
  34. x.pop();
  35. }
  36. }
  37. else x.push(a[i]);
  38. }
  39.  
  40. cout<<x.size()<<endl;
  41. }
  42.  
  43.  
  44. return 0;
  45. }
  46.  
Advertisement
RAW Paste Data Copied
Advertisement