#26766: C++ AC


99980001 (107-07張讓宸)

學校 : 臺北市私立延平高級中學
編號 : 128504
來源 : [203.72.178.2]
最後登入時間 :
2024-04-17 15:32:25
f072. 3. 家裡的後花園 (Garden) -- 2020年5月TOI練習賽新手組 | From: [218.35.155.18] | 發表日期 : 2021-08-24 14:17

#include<bits/stdc++.h>
using namespace std;
int main(){
	int t,a[26],x=0,ff,bf,cff=0,bff=0;
	while(cin>>t){
		for(int i=0;i<t;i++){
			cin>>a[i];
		}
	    for(int i=0;i<=t-1;i++){
	    	if(a[i]==1){
	    		ff=i;
	    		cff=1;
	    		break;
			}
			
			
		}
		
		
		for(int j=t-1;j>=0;j--){
	    	if(a[j]==1){
	    		bf=j;
	    		bff=1;
	    		break;
			}
		}
		
		if(bff=0 and cff==0){
			cout<<0<<endl;
		}
		else if(ff==bf){
			cout<<0<<endl;
		}
		else {
			for(int i=ff+1;i<bf;i++){
			if(a[i]==0 and a[i+1]!=9 and a[i-1]!=9)x+=1;
		}
		
		cout<<x<<endl;
		}
		
		x=0;
		ff=0,bf=0,cff=0,bff=0;
	}
}
 
ZeroJudge Forum