2021-08-30 AcWing 3824. 在校时间
输入样例:
3
5
0 1 0 1 1
7
1 0 1 0 0 1 0
1
0
输出样例:
4
4
0
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int a[110];
int main()
{
int t,n;
cin >> t;
while(t -- )
{
cin >> n;
int cnt=0;
for (int i = 0; i < n; i ++ ) scanf("%d", &a[i]);
for (int i = 1; i < n-1; i ++ ){
if(!a[i]&&a[i-1]&&a[i+1]){
a[i]=1;
}
}
for (int i = 0; i < n; i ++ ){
if(a[i]){
cnt++;
}
}
cout << cnt << endl;
}
return 0;
}
本文来自博客园,作者:泥烟,CSDN同名, 转载请注明原文链接:https://www.cnblogs.com/Knight02/p/15799118.html