반응형
SMALL
신발가게 문제입니다.
collections모듈에서 Counter() 클래스를 사용하여
첫번째 줄에는 신발의 개수
두번째 줄에는 샵에 있는 신발의수
세번째 줄에는 손님의 수
네번째 줄은 신발의 사이즈와 가격을
입력 받아 총 얼마의 수익이 나오는가 입니다.
from collections import Counter
x = int(input()) # 첫줄에 신발 개수
s = list(map(int, input().split())) # 두번째 샵에 있는 신발 개수
n = int(input()) # 고객 수
b = Counter(s) # 손님이 원하는 size: price
sum = 0 # 총 수입
for i in range(n): # 반복문 손님 수 n 만큼
size,price = map(int, input().split()) #size,price 에 s 값 입력 받아 저장
if size in b.keys() and (b[size] != 0): #손님 키값이 있으면
sum += price # 총 합 더하기
b[size] -= 1 # 사이즈에서 제외
print(sum) # 총합 출력
한 참 생각하다가
마음으로 이해하고 남들 푼거 보고
머리로 이해했습니다
그리고 나중에 복습해야죠.............
더보기
from collections import Counter
n, s = input(), Counter(map(int,input().split()))
c = [list(map(int,input().split())) for _ in range (int(input()))]
sum1=0
for i in c :
if i[0] in s.keys() and s[i[0]]>0:
s[i[0]] -=1
sum1+=i[1]
print(sum1)
from collections import Counter
x = int(input())
arr = list(map(int,input().split()))
n = int(input())
b = Counter(arr)
sum = 0
for i in range(n):
size,price = map(int,input().split())
if size in b.keys() and (b[size] != 0):
sum = sum + price
b[size] = b[size] - 1
print(sum)
from collections import Counter
total_shoes = int(input())
shoes = input().split()
shoes_counter = Counter(shoes)
earnings = 0
sizes = []
for _ in range(int(input())):
size, cost = input().split()
sizes.append(size)
if sizes.count(size) <= shoes_counter[size]:
earnings += int(cost)
print(earnings)
반응형
LIST
'IT & 영상관련 > 파이썬python' 카테고리의 다른 글
(알고리즘) 계산복잡도 time complexity (0) | 2020.11.21 |
---|---|
HackerRank] introducation to sets 셋 (저장용) (0) | 2020.08.08 |
HackerRank] Symmetric Difference (저장용) (0) | 2020.08.07 |
HackerRank] .combinations() 조합 (저장용) (2) | 2020.08.06 |
HackerRank] .permutations() 순열 (저장용) (0) | 2020.08.05 |