hdu 1870 栈

来源:互联网 发布:矩阵分解模型 sgd 编辑:程序博客网 时间:2024/05/17 22:29
#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;}

原创粉丝点击