最簡單的棧問題

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<stack>
#include<queue>
using namespace std;
stack<char> p;

int main()
{
    int i,j,n,m;
    char s[1000];
    while(scanf("%s",s)!=EOF)
    {
        m=n=0;
        for(i=0;i<strlen(s);i++)
        {
            if(s[i]=='(')
            {
                p.push(s[i]);
                m++;
            }
            if(s[i]==')')
            {
                 p.pop();
                 n++;
            }
            if(s[i]=='B')
                break;
        }
        printf("%d\n",m-n);
    }
    return 0;
}

點擊打開鏈接
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章