ALGORITHM/PYTHON

백준 BAEKJOON 2484번 주사위 네개 [PYTHON/파이썬]

칼코
반응형

백준 BAEKJOON 2484번 주사위 네개 [PYTHON/파이썬]


<문제 출처>

https://www.acmicpc.net/problem/2484

 

2484번: 주사위 네개

첫째 줄에는 참여하는 사람 수 N이 주어지고 그 다음 줄부터 N개의 줄에 사람들이 주사위를 던진 4개의 눈이 빈칸을 사이에 두고 각각 주어진다.

www.acmicpc.net

<풀이>

1~5번의 조건을 구현해줬다.

4개의 숫자 리스트를 dices에 담고 중복을 제거하기 위해 set 함수를 사용하여 set_dices에 담았다.

tmp 리스트는 set_dices를 통해 같은 숫자가 몇 개씩 들어있는지 확인하는 용도이다.

 

<코드>

N = int(input())
result = []

for _ in range(N) :
    dices = list(map(int,input().split()))
    set_dices = list(set(dices))
    tmp = []
    for i in set_dices :
        tmp.append(dices.count(i))

    if len(set_dices) == 1 :	# 1번 조건
        result.append(50000 + set_dices[0]*5000)
    elif len(set_dices) == 2 :	# 2, 3번 조건
        if len(tmp) == 2 :	# 위에서 만든 tmp 리스트로 2, 3번 차이 판별
            if tmp[0] != tmp[1] :	# 2번 조건
                result.append(10000 + set_dices[tmp.index(max(tmp))] * 1000)
            else :	# 3번 조건
                result.append(2000 + set_dices[0] * 500 + set_dices[1] * 500)
    elif len(set_dices) == 3 :	# 4번 조건
        result.append(1000 + set_dices[tmp.index(max(tmp))] * 100)
    elif len(set_dices) == 4:	# 5번 조건
        result.append(max(dices) * 100)
    
print(max(result))	# 최댓값 출력
반응형