스택, 큐

채종윤·2023년 7월 13일

스택이란?
📔 문제 설명
https://www.acmicpc.net/problem/17608


📝 문제 풀이


💡 내 코드

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 N = Integer.parseInt(br.readLine());
		Stack<Integer> stack = new Stack<>();
		
		int result=0;
		int max=0;
		int count=0;
		
		for (int i = 0; i < N; i++) {
			stack.push(Integer.parseInt(br.readLine()))	;	
		}
			
		for (int i = 0; i < N; i++) {
			max = stack.pop();
			if(max>result) {
				result = max;
				count++;		
		}
					
		}
		System.out.println(count);
	}
}

✍느낀점

profile
안녕하세요. 백앤드 개발자를 목표로 하고 있습니다!

0개의 댓글