본문 바로가기

스택10

[프로그래머스] 고득점Kit (2) - 스택/큐 (파이썬) 1. 기능 개발 (Lv. 2) # 기능개발 def solution(progresses, speeds): days = [] for program, speed in zip(progresses, speeds): temp = (100-program) % speed days.append((100-program)//speed + 1 if temp else (100-program)//speed) answer = [] count = 1 start = days[0] for i, x in enumerate(days): if i+1 = days[i+1]: count += 1 else: answer.append(count) if i + 1 < len(days): start = days.. 2022. 3. 1.
[백준] 9935번 - 문자열 폭발 (파이썬) # 문자열 폭발 str = input().strip() bomb = list(input().strip()) result = [] for i in range(len(str)): result.append(str[i]) if result[-len(bomb):] == bomb: for _ in range(len(bomb)): result.pop() if result: print(*result, sep='') else: print('FRULA') 자료구조 (스택) 1. result에 문자열을 하나씩 넣는다 2. 만약 result의 뒤에서 bomb길이 만큼의 문자열이 bomb와 같으면 bomb의 길이만큼 pop을 해준다. 3. result가 빈 문자열이면 'FRULA'를 아니면 result를 출력 기존의 파이썬 문.. 2022. 1. 28.
[백준] 1918번 - 후위 표기식 (파이썬) # 후위 표기식 from collections import deque from re import L notAlpha = {'+': 1, '-': 1, '*': 2, '/': 2, '(': 0, ')': 0} alpha = deque() sign = [] def popAll(): while alpha: result.append(alpha.popleft()) x = sign.pop() while sign: temp = sign.pop() if x == ')' and temp == '(': break if temp == '(': sign.append(temp) break if notAlpha[x] 1 and sign[-1] != '(' and notAlpha[sign[-1]] 2022. 1. 28.