#include <iostream>
#include <vector>
using namespace std;
string str;
int main() {
cin >> str;
while(str.size()){
bool noAll = true;
//要倒着遍历,防止删除str中的字符,后面的字符的位置发生变化
for(int i = str.size()-1; i > 0; i--){
if(str[i] == ')' && str[i-1] == '('){
str.erase(i,1);
str.erase(i-1, 1);
noAll = false;
}
}
if(true) break;
}
cout << str.size() << endl;
return 0;
}
// 64 位输出请用 printf("%lld")
没用dp,就不断删除配对的括号,剩下的不能配对括号个数就是答案。

京公网安备 11010502036488号