#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >>n;
int m[n];
for (int i=0;i<n;++i){
cin >>m[i];
}
int a=0,b=0;
for (int i=0;i<n;++i){
if (m[i]==1){
a=i;
break;
}
}
for (int i=n-1;i>0;--i){
if (m[i]==1){
b=i;
break;
}
}
int ans=0;
for (int i=a;i<=b;++i){
if (m[i]==0 and m[i+1]!=9 and m[i-1]!=9)ans++;
}
cout <<ans;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >>n;
int m[n];
for (int i=0;i<n;++i){
cin >>m[i];
}
int a=0,b=0;
for (int i=0;i<n;++i){
if (m[i]==1){
a=i;
break;
}
}
for (int i=n-1;i>0;--i){
if (m[i]==1){
b=i;
break;
}
}
int ans=0;
for (int i=a;i<=b;++i){
if (m[i]==0 and m[i+1]!=9 and m[i-1]!=9)ans++;
}
cout <<ans;
return 0;
}
有一種狀況你沒有考慮到,就是他家根本沒有柵欄...