hdu--1870--愚人节的礼物

#include<iostream>
#include<stack>
#include<string>
using namespace std;
int main() 
{
    string str;
    while(getline(cin,str)){
        stack<char> s;
        for(char c:str){
            if(!s.empty() &&s.top()=='(' && c==')')
            {
                s.pop();continue;
            }
            s.push(c);
        }
        int cut=0;
        for(int i=0;i<s.size();++i){
            if(s.top()!='B')cut++;
            else break;
            s.pop();
        }
        cout<<cut<<endl;
    }
    return 0;
}

 

posted @ 2017-02-09 16:00  朤尧  阅读(255)  评论(2编辑  收藏  举报