题解 | #括号匹配深度#
括号匹配深度
https://www.nowcoder.com/practice/a2d5b1875bb0408384278f40d1f236c9
//https://www.nowcoder.com/practice/a2d5b1875bb0408384278f40d1f236c9?tpId=90&tqId=30808&tPage=2&rp=2&ru=%2Fta%2F2018test&qru=%2Fta%2F2018test%2Fquestion-ranking&tab=answerKey #include <iostream> #include <stack> #include <algorithm> using namespace std; int main() { string s; while (cin >> s) { stack<char> st; int countn = 0; for(int i = 0;i<s.size();i++){ if(s[i]=='(') st.push(s[i]); else{ int tem = st.size(); countn = max(countn, tem); st.pop(); } } cout << countn << endl; } }