HDU 1870 愚人节的礼物(栈,括号匹配)

题目链接: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;
}

猜你喜欢

转载自blog.csdn.net/qq_42815188/article/details/90166355