WA50

P3719 [AHOI2017初中组] rexp

+1 同样50分 ``` #include <bits/stdc++.h> using namespace std; string s; int breaket(int l, int r) { int l1, r1, a = 0, ans = 0; for (int i = l; i <= r; i++) { if (s[i] == '|'){ ans = max(ans, a); a = 0; } else if (s[i] == 'a') a++; else if (s[i] == '(') { l1 = i + 1; while (s[i] != ')') i++; r1 = i - 1; a += breaket(l1, r1); } } ans = max(ans, a); return ans; } int main() { cin >> s; cout << breaket(0, s.length() - 1) << endl; } ```
by sophisticate @ 2018-10-09 14:36:39


+1 50 ```cpp #include<bits/stdc++.h> using namespace std; int read() { int x=0,y=1;char ch=getchar(); while(ch>'9'||ch<'0'){if(ch=='-')y=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();} return x*y; } int work(int sum) { char c; while(scanf("%c",&c)!=EOF) { if((c=='a')) sum++; else if(c=='(')sum+=work(0); else if(c=='|')sum=max(sum,work(0)); else return sum; } return sum; } int main() { int mm=work(0); cout<<mm; return 0; } ```
by 问天 @ 2019-06-15 16:43:24


+1 50 ```cpp #include "cstring" #include "cstdio" #include "iostream" using namespace std; int se(int); int main(){ printf("%d",se(0)); return 0; } int se(int k) { char c; while(scanf("%c",&c)!=EOF&&c!='\n') { switch(c) { case 'a' :k++;break; case '(' :k+=se(0);break; case ')' :return k; case '|' :k=max(k,se(0));break; } } return k; } ```
by seven_sin @ 2019-09-20 18:51:19


+1 50 ```cpp #include <cstdio> #include <algorithm> #include <cstring> using namespace std; char now; int dfs() { int ans = 0; while(scanf("%c",&now)!=EOF) { switch(now) { case 'a': { ans++; break; } case '(': { ans+=dfs(); break; } case ')': return ans; case '|': { ans = max(ans, dfs()); break; } } } return ans; } int main() { printf("%d", dfs()); return 0; } ```
by walk_alone @ 2021-01-23 13:02:14


楼上的各位我好像懂了:当遇见符号为“|”时,应当直接返回,而不是继续循环,因为左半边的计算已经停止了。
by walk_alone @ 2021-01-23 13:04:34


`楼上的各位我好像懂了:当遇见符号为“|”时,应当直接返回,而不是继续循环,因为左半边的计算已经停止了。1` 谁能举例说明一下?
by _Sunmoon_ @ 2022-02-09 09:36:39


@[Dragon_Horse](/user/394167) (aaaaa|(aaa|aa))a
by 0410yy @ 2022-07-18 13:58:07


|