-
8931) 제로 - JAVASW Expert Academy 2020. 1. 2. 19:08
문제 )
풀이 )
TC = Test Case 의 수
K = 하나의 테스트 케이스에 들어갈 수(?)num 이란 수로 숫자를 입력받아서 stack 에 넣고 sum 에 계속 더함
만약 num = 0 이라면 stack에 넣었던 값을 빼고 sum 에서도 빼준다.123456789101112131415161718192021222324252627282930313233public class Solution {public static void main(String[] args) throws IOException{BufferedReader br = new BufferedReader(new InputStreamReader(System.in));BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));int TC = Integer.parseInt(br.readLine());for(int i=1; i<=TC; i++) {int K = Integer.parseInt(br.readLine());int sum = 0;Stack<Integer> stack = new Stack<Integer>();for(int j=0; j<K; j++) {int num = Integer.parseInt(br.readLine());if( num == 0) {}else {sum += num;}}}}} cs'SW Expert Academy' 카테고리의 다른 글
8658) Summation - Java (0) 2020.01.02 2072) 홀수만 더하기 JAVA (0) 2019.12.19