본문 바로가기
반응형

프로그래밍54

[프로그래머스] 스택/큐 주식가격 (python) 1차 시도 def solution(prices): answer = [] cnt=0 while prices: sec=prices.pop(0) cnt=0 for i in range(0,len(prices)): if sec 2019. 8. 26.
[프로그래머스] 스택/큐 기능개발 (python) 1차시도 import math def solution(progresses, speeds): answer = [] progresses_left=[] time_left=[] cnt=1 for i in progresses: progresses_left.append(100-i) for i,j in zip(progresses_left,speeds): time_left.append(math.ceil(i/j)) while time_left: tmp=time_left.pop(0) if len(time_left)==0: answer.append(cnt) break elif tmp >= time_left[0]: time_left.pop(0) cnt += 1 else : break answer.append(cnt) cnt=.. 2019. 8. 25.
[프로그래머스] 스택/큐 다리를 지나가는 트럭 (python) 1차 시도 def solution(bridge_length, weight, truck_weights): answer = 0 print(truck_weights) # 줄줄이 도착하는 경우 (모든 트럭 무게 weight: answer += (bridge_length -1) return answer 아이디어 최소시간(min_time)에서 지연 시간을 더해서 결과값을 구하자는 생각이었습니다. (괜찮은 아이디어일 것 같은데) 최소시간은 트럭이 다리에 줄줄이 들어올 수 있어서 줄줄이 다리를 빠져나가는 경우입니다. 모든 트럭 무게의 합이 weigth보다 작거나 같으면 가능한 경우이죠. 지연 시간은 truck_weights에서 2개씩 트럭 무게를 더했을 때 weight를 넘는 경우에 발생을 한다고 생각했었습니다. 놓친.. 2019. 8. 22.
[프로그래머스] 스택/큐 쇠막대기 (python) 처음 저의 코드입니다 (실행시간 초과떴어요) def solution(arrangement): # 필요한 변수 세팅 answer = 0 arr=list(arrangement) laser_end=[] bar=[] bar_start=[] # 레이저의 끝을 구하자 (arr 3개 원소씩 비교하면서) for i in range(0,len(arr),+2): if arr[i]=='(' and arr[i+1]==')': laser_end.append(i+1) continue elif arr[i+1]=='(' and arr[i+2]==')': laser_end.append(i+2) i += 1 # 쇠막대기 후보자들 for i in laser_end: arr[i-1]='x' arr[i]='x' # 쇠막대기 만들자 for i.. 2019. 8. 19.
[프로그래머스] 스택/큐 탑 문제 (python) 작성코드 def solution(heights): answer = [] # (1) answer.append(0) # (2) for i in range(1,len(heights)): flag=False # (3) for j in range(i-1, -1, -1): if heights[j] > heights[i]: answer.append(j+1) flag=False break else: flag=True # (4) if flag: answer.append(0) return answer 코드설명 (1) 맨 왼쪽 탑은 어차피 신호를 보낼 탑이 없음 그러니 answer의 값은 무조건 0 입니다. (2) 왼쪽 탑부터 로직 수행 for i in range(1, len(height)) 두번째 탑 (인덱스 값 1) 부.. 2019. 8. 18.
[프로그래머스] 스택/큐 프린터문제 (Python) 작성코드 (런타임에러 발생) def solution(priorities, location): # (1) 필요한 변수 세팅 print_list=[(p,i) for i,p in enumerate(priorities)] answer=0 p_list=[p for p,i in print_list] p_max=max(p_list) # (2) 실제 로직 수행 while True: # (3) 현재 최상단큐의 중요도가 최대인 경우 출력함 (answer += 1) if p_list[0] >= p_max: a=print_list.pop(0) p_list.pop(0) answer += 1 p_max=max(p_list) # (3-1) 출력하는 문서가 내가 요청한 문서일 경우 if a[1]==location: break # (.. 2019. 8. 18.
반응형