Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

21.03.03 - [BOJ] 10773. 제로 #21

Closed
suhyunsim opened this issue Mar 7, 2021 · 0 comments
Closed

21.03.03 - [BOJ] 10773. 제로 #21

suhyunsim opened this issue Mar 7, 2021 · 0 comments
Assignees
Labels
성공 맞은 문제 스택 stack 실버 BOJ - 실버

Comments

@suhyunsim
Copy link
Owner

suhyunsim commented Mar 7, 2021

문제

핵심 아이디어

  • 0 기준 스택 pop push

어려운 점, 실수

풀이

package main.java.com.poogle.BOJ.Q10773;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;

public class Main {
    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int i, t, sum = 0; /* input */
        int N = Integer.parseInt(br.readLine());
        Stack<Integer> stack = new Stack<Integer>(); /* stack */
        for (i = 0; i < N; i++) {
            t = Integer.parseInt(br.readLine());
            if (t == 0 && !stack.isEmpty()) {
                stack.pop();
            } else if (t != 0) {
                stack.push(t);
            }
        } /* sum */
        while (!stack.isEmpty()) {
            sum += stack.pop();
        }
        System.out.println(sum);
    }
}
@suhyunsim suhyunsim self-assigned this Mar 7, 2021
@suhyunsim suhyunsim added 성공 맞은 문제 스택 stack 실버 BOJ - 실버 자료구조 labels Mar 8, 2021
@suhyunsim suhyunsim added this to the 3월 1주 차 milestone Mar 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
성공 맞은 문제 스택 stack 실버 BOJ - 실버
Projects
None yet
Development

No branches or pull requests

1 participant