牛客 括号画家题解(栈模板题)
发布时间
阅读量:
阅读量
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int rv;
int main()
{
string s;
int r1 = 0, r2 = 0;
cin>>s;
stack<char>st;
for(int i = 0; i < s.size(); i ++ ){
if(s[i] == '(' || s[i] == '[' || s[i] == '{'){
st.push(s[i]);
}
else{
if(!st.empty()){
if((s[i] == ')' && st.top() == '(') || (s[i] == ']' && st.top() == '[') || (s[i] == '}' && st.top() == '{')){
st.pop();
r1 += 2;
}
else{
r2 = max(r1, r2);
r1 = 0;
while(
全部评论 (0)
还没有任何评论哟~
