import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner input = new Scanner(System.in); int[] arr = new int[35]; int i; for (i = 1; ; i++) { arr[i] = input.nextInt(); if (arr[i] == 0) break; } int cnt = 0, sum = 0; //System.out.println(i); if (arr[0] == 1) cnt++; else sum = 2; for (int j = 1; j < i; j++) { if (arr[j] == 1) cnt++; else { if (arr[j - 1] == 1) sum = 2; if (arr[j - 1] == 2) sum += 2; cnt += sum; if (arr[j + 1] == 0) sum = 0; } } System.out.println(cnt); } }
08-17
148
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)