

//
// main.swift
// BOJ
//
// Created by leehwajin on 2022/12/28.
//
import Foundation
let times = Int(readLine()!)!
var intArr:Array<Int> = []
for _ in 0..<times{
var input = readLine()!.split(separator: " ").map{$0}
switch String(input[0]){
case "push" :
intArr.append(Int(input[1])!)
case "top" :
if(intArr .isEmpty){
print("-1")
continue
}
print(intArr[intArr.endIndex-1])
case "pop" :
if(intArr .isEmpty){
print("-1")
continue
}
print(intArr[intArr.endIndex-1])
intArr.remove(at:intArr.endIndex-1)
case "size" :
print(intArr.count)
case "empty" :
intArr.isEmpty ? print("1") : print("0")
default:
break
}
}
오랜만에 이지......ㅎㅎㅎㅎㅎㅎ
'백준' 카테고리의 다른 글
| 스위프트 백준 2292 벌집 (0) | 2022.12.29 |
|---|---|
| [SWIFT]백준1920 수찾기/이진탐색/시간복잡도 (1) | 2022.12.29 |
| [SWIFT]백준9012 괄호 (0) | 2022.12.29 |
| [SWIFT]2839 설탕배달 (0) | 2022.12.27 |
| [SWIFT] 백준2869 달팽이는 올라가고싶다 (5) | 2022.12.23 |