题目链接:HDU 1870 愚人节的礼物
实际上不用栈,用栈的思想即可
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
using namespace std;
typedef long long ll;
const int MOD = 10000007;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const int maxn = 1010;
int a[maxn];
int main()
{
string s;
while(cin>>s)
{
int top = 0;
for(int i=0;;i++)
{
if(s[i]=='B') break;
if(s[i]=='(') top++;
if(s[i]==')') top--;
}
printf("%d\n",top);
}
return 0;
}