[백준]2484번 - 주사위 네개

JinHo Choi·2020년 11월 18일
0

algorithm

목록 보기
3/3

👉   Problem

🕐   Environment

  • 언어 - Python3
  • 시간 제한 - 1초
  • 메모리 제한 - 128MB
  • Input 예제
    • 첫째 줄에는 참여하는 사람 수 N이 주어지고 그 다음 줄부터 N개의 줄에 사람들이 주사위를 던진 4개의 눈이 빈칸을 사이에 두고 각각 주어진다.
      4
      3 3 3 3
      3 3 6 3
      2 2 6 6
      6 2 1 5

💡   Code

# 상금 계산 함수
def CalculateReward(diceList):
    result = 0
    if len(set(diceList)) == 1: # 모두 같은 눈
        result = 50000 + diceList[0]*5000
    elif len(set(diceList)) == 2: # 같은 눈 3개 or 같은 눈 2개 2쌍
        if diceList[1] == diceList[2]:
            result = 10000 + diceList[1]*1000
        else:
            result = 2000 + diceList[1]*500 + diceList[2]*500
    elif len(set(diceList)) == 3:   # 같은 눈 2개 1쌍
        if diceList[0] == diceList[1]:
            result = 1000 + diceList[0]*100
        elif diceList[1] == diceList[2]:
            result = 1000 + diceList[1]*100
        else:
            result = 1000 + diceList[2]*100
    else:   # 모두 다른 경우
        result = diceList[3]*100
    return result


numberOfPerson = int(input())
reward = []
for i in range(numberOfPerson):
    diceList = sorted(list(map(int, input().split())))
    reward.append(CalculateReward(diceList))

print(max(reward))

😃   Review

Set을 이용한 중복을 제거하는 것이 핵심인 문제이다. 주어진 조건에 따른 정확하고 간단한 예외처리를 할 수 있는지 물어보는 문제인 것 같다.

1개의 댓글

comment-user-thumbnail
2021년 3월 22일

안녕하세요! 풀이 너무 깔끔하십니다. 배우고 갑니다 ^^

답글 달기