[백준/Python] 10828번 - 스택

2023. 9. 1. 02:34·Algorithm/BaekJoon
import sys
input = sys.stdin.readline

stack = []
for _ in range(int(input())):
  commands = input().rstrip().split()
  if commands[0] == "push": stack.append(int(commands[1]))
  elif commands[0] == "pop": print(-1) if not stack else print(stack.pop())
  elif commands[0] == "size": print(len(stack))
  elif commands[0] == "empty": print(0) if stack else print(1)
  elif commands[0] == "top": print(stack[-1] if stack else -1)

스택에 대한 아주 기초적인 알고리즘 문제다.

 

 

Learned

  • print문 안에서 조건문을 쓰면 특정 조건이 만족했을 때 값을 print 해준다

'Algorithm > BaekJoon' 카테고리의 다른 글

[백준/Python] 2573번 - 빙산  (0) 2023.09.06
[백준/Python] 2170 - 선 긋기  (0) 2023.09.02
[백준/Python] 1874번 - 스택 수열  (0) 2023.09.02
[백준/Python] 2493번 - 탑  (0) 2023.09.01
[백준/Python] 15903번 - 카드 합체 놀이  (0) 2023.09.01
'Algorithm/BaekJoon' 카테고리의 다른 글
  • [백준/Python] 2170 - 선 긋기
  • [백준/Python] 1874번 - 스택 수열
  • [백준/Python] 2493번 - 탑
  • [백준/Python] 15903번 - 카드 합체 놀이
빵빵0
빵빵0
(아직은) 공부하고 정리하는 블로그입니다.
  • 빵빵0
    Hack Your World
    빵빵0
  • 전체
    오늘
    어제
    • 분류 전체보기 (92)
      • Error Handling (7)
      • Project (5)
        • MEV (2)
      • Architecture (0)
        • API (0)
        • Cache (0)
        • 사소한 고민거리 (0)
      • Computer Science (4)
        • Data Structure (2)
        • Database (1)
        • Cloud (0)
        • OS (0)
        • Infra, Network (1)
        • AI (0)
      • Language (8)
        • Go (8)
        • Rust (0)
        • Python (0)
        • Java (0)
      • Algorithm (40)
        • BaekJoon (18)
        • Programmers (7)
        • LeetCode (6)
        • NeetCode (9)
      • SW Books (9)
        • gRPC Up & Running (1)
        • System Design Interview (2)
        • 스프링 입문을 위한 자바 객체지향의 원리와 이해 (6)
        • 블록체인 해설서 (0)
        • 후니의 쉽게 쓴 CISCO 네트워킹 (0)
      • BlockChain (4)
        • Issues (0)
        • Research (4)
        • Tech (0)
      • Own (8)
        • TIR(Today I Read) (3)
        • Personal (2)
        • Novel (0)
        • Memo (3)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    Hash Table
    candlechart
    goroutine
    블록체인
    큐
    go
    프로그래머스
    BEAKJOON
    LeetCode
    MongoDB
    Palindrome
    MEV
    BaekJoon
    two pointer
    NeetCode
    blockchain
    Python
    Programmers
    EVM
    chart
    2024
    스택
    golang
    Greedy
    백준
    BFS
    KBW
    DP
    context
    ethereum
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.4
빵빵0
[백준/Python] 10828번 - 스택
상단으로

티스토리툴바