[python/파이썬] 백준 BEAKJOON 2476번: 주사위 게임
https://www.acmicpc.net/problem/2476
2476번: 주사위 게임
첫째 줄에는 참여하는 사람 수 N이 주어지고 그 다음 줄부터 N개의 줄에 사람들이 주사위를 던진 3개의 눈이 빈칸을 사이에 두고 각각 주어진다.
www.acmicpc.net
1) 문제

2) 시행 착오
a) 1차 시도
n=int(input())
for i in range(1,n+1):
a,b,c=map(int, input().split())
if a==b==c:
print(int(10000+(a*1000)))
elif a==b and a!=c:
print(int(1000+(a*100)))
elif b==c and b!=a:
print(int(1000+(b*100)))
elif a==c and a!=b:
print(int(1000+(a*100)))
elif a>b>c:
print(int(a*100))
elif a>c>b:
print(int(a*100))
elif b>a>c:
print(int(b*100))
elif b>c>a:
print(int(a*100))
elif c>a>b:
print(int(c*100))
elif c>b>a:
print(int(c*100))
b) 1차 시도 - 틀린 이유
내 코드의 출력값: 무조건 입력값의 마지막 줄을 계산한 값이 출력값이 된다.
정답의 출력값: 각 줄을 계산한 결괏값을 비교해서 그 중 가장 큰 값이 출력값이 되어야 함
-
그렇다면 각 줄을 따로따로 계산한 뒤 비교해주는 방법을 사용해야 한다.
어쩌다가 내가 전에 풀었던 알고리즘 문제를 봤는데 list 와 max 를 사용한 것을 보았다.
'최댓값' 을 구해야 하므로 list와 max를 이용하는 것도 방법이 될 수 있을 것 같다.
그런데 어떻게 코드로 구현해야 하는 지가 막막했다.
c) 2차 시도
result=0
maximum=0
n=int(input())
for i in range(n):
a, b, c=map(int, input().split())
if a==b==c:
result=int(10000+(a*1000))
elif a==b and a!=c:
result=int(1000+(a*100))
elif b==c and b!=a:
result=int(1000+(b*100))
elif a==c and a!=b:
result=int(1000+(a*100))
elif a>b>c:
result=int(a*100)
elif a>c>b:
result=int(a*100)
elif b>a>c:
result=int(b*100)
elif b>c>a:
result=int(a*100)
elif c>a>b:
result=int(c*100)
else:
result=int(c*100)
if maximum<result:
maximum=result
print(maximum)
d) 2차 시도 - 틀린 이유
진짜 모르겠다...
어느 부분이 틀린 건지 알 수 있다면 좋겠다...
파이썬 고수분들 혹시나 이 글을 보신다면 정답을 댓글로 알려주시면 감사하겠습니다.
-

조금씩 수정해보았으나 결국 위의 코드를 마지막으로 포기
3) 문제 풀이/ 정답
결국 인터넷에 올라와 있는 다른 분의 코드를 제출했다.
아마 내가 짠 코드는 조건문 부분에서 틀렸다고 한 것 같은데, 여전히 정확히 어느 부분이 틀렸는지 이해가 가지 않는다...
[출처] [python] BAEKJOON _ 2476번|작성자 EllieZzhan
https://blog.naver.com/pcy921118/222551610986
[python] BAEKJOON _ 2476번
주사위 게임 참여하는 사람의 수를 case에 담아주고, 결과를 받을 result 변수를 선언해준다. 참여하는 사...
blog.naver.com
case = int(input())
result = 0
for _ in range(case):
a, b, c = map(int, input().split())
if a == b == c:
result = max(result, 10000+a*1000)
elif a == b:
result = max(result, 1000+a*100)
elif a == c:
result = max(result, 1000+a*100)
elif b == c:
result = max(result, 1000+b*100)
else:
result = max(result, 100*max(a, b, c))
print(result)

'Algorythm > 백준 BEAKJOON' 카테고리의 다른 글
[python/파이썬] 백준 BEAKJOON 11557번: Yangjojang of The Year (0) | 2023.05.31 |
---|---|
[python/파이썬] 백준 BEAKJOON 22966번: 가장 쉬운 문제를 찾는 문제 (0) | 2023.05.22 |
[python/파이썬] 백준 BEAKJOON 16430번: 제리와 톰 (0) | 2023.05.17 |
[python/파이썬] 백준 BEAKJOON 2754번: 학점 계산 (2) | 2023.05.17 |
[python/파이썬] 백준 BEAKJOON 4101번: 크냐? (0) | 2023.05.09 |