天天写算法之(队列)愚人节的礼物

这个题目之前就开过,就是看(在B出现之前不被抵消掉的数量。

代码:

#include<iostream>
#include<cstdio>
#include<string.h>
#include<stack>
#include<queue>
#include<queue>
using namespace std ;
#define MAX 400
int main(){
  string s ;
  while(cin >> s) {
    queue<char> qe;
    int num =0;
    for (int i = 0 ; i <strlen(s.c_str());i++)
    {
        if(s[i]=='B')
        {
            break;
        }
        if(s[i]=='(')
        {
            qe.push('(');
        }
        if(s[i]==')')
            if(!qe.empty())
                qe.pop();
    }
    cout << qe.size()<<endl;
  }
}

猜你喜欢

转载自blog.csdn.net/qq_36616268/article/details/80160193