题解 CF1428C 【ABBB】

· · 题解

    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<cstring> 
    using namespace std;
    const int Maxn=200000+5;
    int T,n,top,cnt;
    char s[Maxn],s2[Maxn],st[Maxn];
    int main()
    {   scanf("%d",&T);
        while(T--)
        {   top=0;cnt=0;
            scanf("%s",s+1);
            n=strlen(s+1);
            for(int i=1;i<=n;i++)
            {   if(s[i]=='B'&&top>0)top--;
                else st[++top]=s[i];
            }
            printf("%d\n",top);
        }
        return 0;
    }