Skip to content

Commit 59e3f16

Browse files
committed
[BOJ] #2503.숫자 야구 / 실버3 / 30(X)
1 parent a93d66f commit 59e3f16

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import sys
2+
input = sys.stdin.readline
3+
from itertools import permutations
4+
5+
N = int(input().strip()) # 질문 횟수
6+
questions = [list(map(int, input().split())) for _ in range(N)] # 질문 리스트
7+
8+
# 1부터 9까지의 숫자 중 3개를 뽑는 순열
9+
nums = list(permutations(range(1,10), 3))
10+
cnt = 0 # 가능한 경우의 수
11+
12+
# 두 수를 비교하여 스트라이크와 볼을 반환
13+
def strike_and_ball(num1, num2):
14+
strike = sum(a == b for a, b in zip(num1, num2))
15+
ball = sum(a in num2 for a in num1) - strike
16+
return strike, ball
17+
18+
for num in nums:
19+
num_str = ''.join(map(str, num)) # 순열을 문자열로 변환
20+
valid = True # 가능한 숫자인지 판별
21+
22+
for q_num, q_strike, q_ball in questions:
23+
q_str = str(q_num) # 입력된 숫자도 문자열 변환
24+
strike, ball = strike_and_ball(num_str, q_str)
25+
if strike != q_strike or ball != q_ball:
26+
valid = False
27+
break # 하나라도 불가능하면 더 볼 필요 없음
28+
29+
if valid:
30+
cnt += 1
31+
32+
print(cnt)
33+

0 commit comments

Comments
 (0)