한줄에 조건문
-
백준 10828번 어떻게 풀었나, 스택(Stack) 구현백준 2023. 1. 5. 00:01
푼 방법 문제에 적혀있는 데로 구현 해 주었다.. 더 알고 싶은 부분 한줄에 조건문 쓰는 법 if 아래 두 코드는 똑같다. if animal is dog: ret = dog if animal is dog: ret = dog if - else 결과 = A if 조건 else B if - elif - else 결과 = A if 조건 else B if 조건 else C 코드 import sys N = int(sys.stdin.readline()) stack = [] for i in range(N): cmd = sys.stdin.readline().strip() # push X: 정수 X를 스택에 넣는 연산이다. if "push" in cmd: stack.append(cmd[5:]) # pop: 스택에서 가장 ..