栈
1.小欧的括号运算
https://www.nowcoder.com/questionTerminal/0bcbd996fe234e25960abf0c82327dc2?orderByHotValue=1&page=1&onlyReference=false
#include <iostream> #include <stack> using namespace std; int main() { string str; cin >> str; stack<char> stk; for (int i = 0; i < str.size(); i++) { if (str[i] == '(') { stk.push(str[i]); } else { if (!stk.empty()&&stk.top() == '(') { stk.pop(); while (!stk.empty()&&stk.top() == '(') { stk.pop(); } stk.push('('); } else { stk.push(str[i]); } } } cout << stk.size() << endl; } // 64 位输出请用 printf("%lld")
浙公网安备 33010602011771号