思路:

递归计算。

实现:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 string s; int p = 0;
 4 int dfs()
 5 {
 6     int ans = 0, t = 0;
 7     while (true)
 8     {
 9         if (s[p] == '(') { p++; t += dfs(); }
10         else if (s[p] == 'x') { t++; p++; }
11         else if (s[p] == '|') { ans = max(ans, t); t = 0; p++; }
12         else
13         {
14             ans = max(ans, t);
15             p++;
16             break;
17         }
18     }
19     return ans;
20 }
21 int main()
22 {
23     cin >> s;
24     cout << dfs() << endl;
25     return 0;
26 }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-30
  • 2022-12-23
  • 2022-01-15
  • 2021-11-22
  • 2022-03-01
  • 2022-01-07
  • 2022-12-23
相关资源
相似解决方案