- [ 코딩테스트/백준 ]백준(BAEKJOON) 10828 스택 - Kotlin2024-07-30 18:02:42https://www.acmicpc.net/problem/10828 풀이import java.io.BufferedReaderimport java.io.InputStreamReaderlateinit var stack: IntArray // 스택 저장 배열var ptr = -1 // 스택의 현재 위치, -1로 현재 스택이 비어있다는 걸로fun main() { val br = BufferedReader(InputStreamReader(System.`in`)) val testCase = br.readLine().toInt() stack = IntArray(testCase) for (i in 0.. println(top()) "pop" -> println(pop())..
- [ 코딩테스트/백준 ]백준(BAEKJOON) 10828 스택 - Python2023-11-21 14:37:33풀이코드 import sys input = sys.stdin.readline # readline하지 않으면 시간초과 뜸. n = int(input()) arr = [] # 스택 배열 for _ in range(n): # n번 명령 처리하기 command = input().split() # 공백 분리 # 푸시 if command[0] == 'push': arr.append(int(command[1])) # 스택에 요소 추가 # 팝 elif command[0] == 'pop': if len(arr) == 0: print(-1) # 비어있으면 else: print(arr.pop()) # 스택 마지막 요소 제거하고 print # 사이즈 elif command[0] == 'size': print(len(arr))..