backjeon/Bronze

Baekjoon(백준) - 2480 (주사위 세개) | Python

SecLogs YJ 2026. 3. 1. 19:44
import sys

a, b, c = map(int, sys.stdin.readline().split())
[a, b, c] = sorted([a, b, c])

if a == b and a == c:
    print(10000 + (a * 1000))
elif a == b or b == c:
    print(1000 + (b * 100))
else:
    print(c * 100)

사용된 개념

1. 입력 처리 - sys.stdin.readline()

import sys
a, b, c = map(int, sys.stdin.readline().split())
  • sys.stdin.readline()
    → 표준 입력을 빠르게 받기 위한 함수
  • split()
    → 공백 기준으로 문자열 분리
  • map(int, ...)
    → 각 요소를 정수형으로 변환

백준은 입력 데이터가 많을 수 있기 때문에 기본 input()보다 빠른 sys.stdin.readline()을 자주 사용한다.

 

2. 정렬 - sorted()

[a, b, c] = sorted([a, b, c])

 

 

  • sorted() → 리스트를 오름차순 정렬
  • 반환값은 새로운 리스트

3. 조건문 - if . elif / else + 논리 연산자 and / or

if a == b and a == c:
    print(10000 + (a * 1000))
elif a == b or b == c:
    print(1000 + (b * 100))
else:
    print(c * 100)

 

  • 세 개가 모두 같은 경우 (a == b and a ==c)
  • 두 개만 같은 경우 (a == b or b ==c) ← 정렬했기 때문에 b는 항상 같은 값!
  • 모든 다른 경우

🧐 TIP은 정렬을 이용하여 경우의 수를 줄이는 것!