Untitled
unknown
plain_text
3 years ago
485 B
7
Indexable
#include<iostream> #include<stack> #include<algorithm> using namespace std; string s; stack<int> str; int main(){ int count = 0,Max = 0; s = "{{}()[][(]}"; str.push(-1); for(int i = 0;i < s.length();i++){ char c = (char)s[i]; if(c == '(' || c == '{' || c == '['){ str.push(i); } else{ str.pop(); if(str.empty()){ str.push(i); } else{ int len = i - str.top(); Max = max(Max,len); } } } cout << Max; return 0; }
Editor is loading...