슈콩

[SWEA] 제로 본문

Algorithms/SWEA

[SWEA] 제로

shukong 2025. 11. 14. 20:21

 

 

[문제]

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AW5jBWLq7jwDFATQ

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

 

 

[소스 코드]

import java.io.*;
import java.util.*;
public class Solution {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int T = Integer.parseInt(br.readLine());
		for(int tc=1;tc<=T;tc++) {
			int k = Integer.parseInt(br.readLine());
			Stack<Integer> s = new Stack<>();
			for(int i=0;i<k;i++) {
				int v = Integer.parseInt(br.readLine());
				if(v==0) s.pop();
				else s.push(v);
			}
			int result = 0;
			while(!s.isEmpty()) {
				result += s.pop();
			}
			System.out.println("#"+tc+" "+result);
		}
	}
}

'Algorithms > SWEA' 카테고리의 다른 글

[SWEA] 알파벳 공부  (0) 2025.11.14
[SWEA] 힙  (0) 2025.11.14
[SWEA] 안경이 없어!  (0) 2025.11.14
[SWEA] 등차수열 만들기  (0) 2025.11.14
[SWEA] 최장 공통 부분 수열  (0) 2025.11.14