#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stack>
using namespace std;
char str[1000+100];
stack<char> q;
int main()
{
int cnt=0;
char top;
while(~scanf("%s",str))
{
while(!q.empty())
q.pop();
cnt=1;
q.push(str[0]);
for(int i=1;str[i];i++)
{
if(!q.empty())
top=q.top();
if(str[i]=='(')
{
cnt++;
q.push(str[i]);
}
else if(str[i]==')' && top=='(')
{
cnt--;
q.pop();
}
else if(str[i]=='B')
break;
}
printf("%d\n",cnt);
}
return 0;
}
hdu 1870 栈
最新推荐文章于 2021-07-25 19:15:49 发布