HDU 5479 Scaena Felix

水题,括号匹配,有几对匹配了,答案就是那个...

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

int Stack[1005];
int top;

int main()
{
    int T;
    char a[1005];
    scanf("%d",&T);
    while(T--)
    {
        int  ans=0;
        top=-1;
        scanf("%s",a);
        int len=strlen(a);
        for(int i=0; i<len; i++)
        {
            if(a[i]=='(')
            {
                top++;
                Stack[top]=1;
            }
            else
            {
                if(Stack[top]==1)
                {
                    top--;
                    ans++;
                }
                else
                {
                    top++;
                    Stack[top]=2;
                }
            }
        }

        printf("%d
",ans);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/zufezzt/p/4841786.html