본문 바로가기
알고리즘

(백준) 10773번 : 제로 - 자바[JAVA]

by 코딩개발 2021. 9. 10.
728x90
반응형

package test;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Test_10773 {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int line = Integer.parseInt(br.readLine());
		int[] sum = new int[line];
		int index = 0;
		int total = 0;


		for(int i = 0; i < line; i++) {
			sum[index] = Integer.parseInt(br.readLine());
			if(sum[index] == 0) {
				index--;
			} else {
				index++;
			}
		}

		for(int i = 0; i < index; i++) {
			total += sum[i];
		}

		System.out.println(total);
	}
}
728x90
반응형

댓글