


코딩테스트 연습 - 주사위 게임 3 | 프로그래머스 스쿨 (programmers.co.kr)
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
나의 코드
from collections import Counter
def solution(a, b, c, d):
answer = 0
game_list = [a,b,c,d]
# 주사위 딕셔너리 만들고 개수로 정렬
game = Counter(game_list)
game = dict(sorted(game.items(), key=lambda x:x[1], reverse=True))
print(game)
# 조건에따라 answer 처리해주자
if len(game) == 1:
answer = 1111*list(game.keys())[0]
elif len(game) == 2:
if max(list(game.values())) == 3:
answer = (10*list(game.keys())[0]+list(game.keys())[1])**2
elif max(list(game.values())) == 2:
answer = (list(game.keys())[0] + list(game.keys())[1]) * abs(list(game.keys())[0] - list(game.keys())[1])
elif len(game) == 3:
answer = list(game.keys())[1] * list(game.keys())[2]
else:
answer = min(list(game.keys()))
print(answer)
return answer
'코딩테스트 파이썬 > 파이썬 프로그래머스 1단계' 카테고리의 다른 글
| [PCCP 기출문제] 1번 / 붕대 감기 (0) | 2024.01.06 |
|---|---|
| 가장 많이 받은 선물 (0) | 2024.01.06 |
| 정수를 나선형으로 배치하기 (0) | 2023.10.26 |
| 공원 산책 (0) | 2023.10.06 |
| 달리기 경주 (0) | 2023.10.05 |