E.cpp 432 B

123456789101112131415161718192021
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4. string s;
  5. while (cin >> s) {
  6. stack<char> S;
  7. size_t Max = 0;
  8. for (size_t i = 0; i < s.size(); i++) {
  9. if (s[i] == '(') {
  10. S.push(s[i]);
  11. Max = max(Max, S.size());
  12. } else if (s[i] == ')') {
  13. S.pop();
  14. }
  15. }
  16. cout << Max << endl;
  17. }
  18. return 0;
  19. }