0
点赞
收藏
分享

微信扫一扫

2021-08-30 AcWing 3824. 在校时间

2021-08-30 AcWing 3824. 在校时间_ios

输入样例:

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;
}


举报

相关推荐

0 条评论