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
반응형
'알고리즘' 카테고리의 다른 글
(백준) 2902번 : KMP는 왜 KMP일까? - 자바[JAVA] (0) | 2021.09.10 |
---|---|
(백준) 2576번 : 홀수 - 자바[JAVA] (0) | 2021.09.10 |
(백준) 10872번 : 팩토리얼 - 자바[JAVA] (0) | 2021.09.10 |
(백준) 10093번 : 숫자 - 자바[JAVA] (0) | 2021.09.08 |
(백준) 1712번 : 손익분기점 - 자바[JAVA] (0) | 2021.09.08 |
댓글