123456789101112131415161718192021222324 |
- #include<bits/stdc++.h>
- using namespace std;
- //问题 H: 序列的深度 用一个变量x记住当前所在位置的深度,维护这个变量x的曾经最大值即可
- int main() {
- char s[100000];
- while (cin >> s) {
- int x = 0;
- int Max = 0;
- for (size_t i = 0, n = strlen(s); i < n; i++) {
- if (s[i] == '(') {
- ++x;
- if (x > Max)Max = x;
- } else if (s[i] == ')')--x;
- }
- cout << Max << endl;
- }
- return 0;
- }
|