前言
心态爆题
- Codeblocks导致电脑宕机
- 超出String读入
思路
因为要求的是连续子串
对于每一次匹配我们就统计一次答案
如果不匹配那么就将当前的节点加入栈中
Mycode
typedef priority_queue<int,vector<int>,greater<int>> Pri_m;
typedef pair<int,int> pii;
typedef pair<char,int> pci;
typedef vector<int> VI;
map<int,int> mp;
const int N = 1e5+10;
void solve()
{
stack<pci> stk;
int ans = 0 ;
//cout<<n<<endl;
char c;
int i =0 ;
while(c = getchar(),i++,~c){
if(stk.size() &&
((c == ')' && stk.top().x == '(')
||(c == ']') && stk.top().x == '['
||(c == '}') && stk.top().x == '{')){
stk.pop();
if(stk.size()){
ans =max(ans,i-stk.top().y);
}else ans = max(ans,i);
}else{
stk.push({c,i});
}
}
cout<<ans<<endl;
}