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

posted @ 2021-08-30 19:49  泥烟  阅读(24)  评论(0编辑  收藏  举报