File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
learntosurf/Implementation Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 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+
You can’t perform that action at this time.
0 commit comments