C++题解
2024-08-19 16:49:42
发布于:四川
17阅读
0回复
0点赞
AC代码
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, ans = 0, sum = 0, a[1010] = {0}, ans1 = 0;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
if (n == 0) {
cout << 0 << endl;
return 0;
}
for (int i = 1; i < n; ++i) {
if (a[i] == 1) {
++ans1;
continue;
} else {
break;
}
}
if (ans1 == n - 1) {
cout << 0;
return 0;
}
for (int i = 0; i < n; ++i) {
if (a[i] == 1) {
ans = 0;
for (int j = i; j < n; ++j) {
if (a[j] == 0) {
j = n;
sum = max(sum, ans);
}
++ans;
}
}
}
cout << sum + 1 << endl;
return 0;
}
这里空空如也
有帮助,赞一个