https://www.acmicpc.net/problem/10773
const fs = require('fs');
const input = fs.readFileSync('/dev/stdin').toString().trim().split("\n");
const N = Number(input[0]);
const stack = [];
for(let i = 0 ; i < N ; i++) {
if(Number(input[i+1]) !== 0 ) stack.push(Number(input[i+1]));
else stack.pop();
}
let answer = 0;
stack.forEach((s) => {
answer += s;
});
console.log(answer);
728x90
'Algorithm&CodingTest > Baekjoon' 카테고리의 다른 글
[Baekjoon] [2750] 수 정렬하기 (0) | 2023.02.09 |
---|---|
[Baekjoon] [1316] 그룹 단어 체커 (0) | 2023.02.09 |
[Baekjoon] [1157] 단어 공부 (0) | 2023.02.09 |
[Baekjoon] [4344] 평균은 넘겠지 (0) | 2023.02.09 |
[Baekjoon] [2941] 크로아티아 알파벳 (0) | 2023.02.09 |