Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
Tags
- 수학
- MYSQL
- BFS
- 파이썬
- BOJ
- level2
- programmers
- 브루트포스
- level1
- 코딩테스트
- 가상메모리 관리
- dfs
- 다익스트라
- N과M
- 프로그래머스
- 가상메모리
- DP
- 힙
- 구현
- 스택
- 딕셔너리
- 재귀
- 백준
- level3
- 운영체제
- 그리디
- level0
- 다이나믹 프로그래밍
- dict
- python
Archives
- Today
- Total
동캄의 코딩도장
프로그래머스 level2 [할인 행사] 파이썬 본문
https://school.programmers.co.kr/learn/courses/30/lessons/131127
# 프로그래머스 level2 할인 행사
def solution(want, number, discount):
answer = 0
dic=dict()
l=[]
for i in range(len(want)): #초기 값 세팅
dic[want[i]]=number[i]
for i in range(10): # 첫날~10일차까지 할인품목 체크
inStuff=discount[i]
if inStuff in want:
dic[inStuff]-=1
l.append(inStuff)
for wantStuff in want: #모두 할인 받는지 체크
if dic[wantStuff]>0:
break
else:
answer+=1
for i in range(10,len(discount)): # N일차~N+10일차까지 할인품목 체크
outStuff=l.pop(0)
if outStuff in want:
dic[outStuff]+=1
inStuff=discount[i]
l.append(inStuff)
if inStuff in want:
dic[inStuff]-=1
for wantStuff in want: #모두 할인 받는지 체크
if dic[wantStuff]>0:
break
else:
answer+=1
return answer
딕셔너리를 이용하여 해결하였다.
want의 길이가 10이 넘지 않으므로, "for 물건 in want "구문을 사용하였다.
'코테 > 프로그래머스' 카테고리의 다른 글
프로그래머스 level2 [뒤에 있는 큰 수 찾기] 파이썬 (0) | 2023.04.05 |
---|---|
프로그래머스 level2 [숫자 변환하기] 파이썬 (0) | 2023.04.05 |
프로그래머스 level2 [연속 부분 수열 합의 개수] 파이썬 (0) | 2023.04.05 |
프로그래머스 level2 [귤 고르기] 파이썬 (0) | 2023.04.05 |
프로그래머스 level1 [푸드파이트 대회] 파이썬 (0) | 2023.04.04 |