-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathABBB.cpp
57 lines (49 loc) · 953 Bytes
/
ABBB.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Question Link:
#include<bits/stdc++.h>
#include<cmath>
#include<algorithm>
#include<string.h>
# define mod 1000000007
using namespace std;
typedef long long int lli;
void solve()
{
//write your code here
string s;
cin >> s;
stack<char>sr;
sr.push(s[0]);
for(int i=1;i<s.size();i++)
{
if(sr.empty()) sr.push(s[i]);
else
{
if(sr.top()=='B' && s[i]=='B') sr.pop();
else if (sr.top() == 'A' && s[i] == 'B')
{
sr.pop();
}
else
{
sr.push(s[i]);
}
}
}
cout << sr.size() << "\n";
}
int main()
{
#ifndef ONLINE_JUDGE
freopen ("A:/c++/inputf.in", "r", stdin);
freopen ("A:/c++/outputf.in", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while(t--)
{
solve();
}
return 0;
}