CF 26 B. Regular Bracket Sequence

题目:Regular Bracket Sequence

思路:水模拟,不要以为是那个求dp的那个 ==

#include <cstdio>
#include <iostream>
#include <cmath>
#include <stack>
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{
    string str;
    stack<char>s;
    while(!s.empty())
        s.pop();
    cin>>str;
    for(int i=0;i<str.size();i++)
    {
        if(str[i]=='(')
            s.push(str[i]);
        else
        {
            if(!s.empty()&&s.top()=='(')
            {
                s.pop();
            }
            else
                s.push(str[i]);
        }
    }
    cout<<str.size()-s.size()<<endl;
    return 0;
}
View Code

 

posted @ 2013-07-14 11:06  over_flow  阅读(144)  评论(0编辑  收藏  举报