hwangnk1004 / Algorithm

0 stars 0 forks source link

StepByStep #점수 구하기 #259

Open hwangnk1004 opened 4 years ago

hwangnk1004 commented 4 years ago

import java.util.Scanner;

public class Main { public static void main(String args[]) {

    Scanner scanner = new Scanner(System.in);

    int n = scanner.nextInt();

    int[] arr = new int[n];
    int count = 0;
    int sum = 0;

    for(int i = 0; i<arr.length; i++) {
        arr[i] = scanner.nextInt();

        if (arr[i] == 1) {
            count++;
            sum+=count;
        } else if (arr[i] == 0) {
            count = 0;
        }

    }
    System.out.println(sum);

}

}