입력
첫째 줄에는 민혁이가 영수에게 몇 번이나 질문을 했는지를 나타내는 1 이상 100 이하의 자연수 N이 주어진다. 이어지는 N개의 줄에는 각 줄마다 민혁이가 질문한 세 자리 수와 영수가 답한 스트라이크 개수를 나타내는 정수와 볼의 개수를 나타내는 정수, 이렇게 총 세 개의 정수가 빈칸을 사이에 두고 주어진다.
출력
첫 줄에 영수가 생각하고 있을 가능성이 있는 답의 총 개수를 출력한다.
예제 입력
4
123 1 1
356 1 0
327 2 0
489 0 1
예제 출력
2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
n = int(input())
arr = [[0]*3 for _ in range(n)]
possible = []
result = []
for i in range(n):
arr[i] = list(map(int, input().split()))
for j in range(100, 1000):
digit = str(j)
if digit[0] != digit[1] and digit[1] != digit[2] and digit[0] != digit[2] and '0' not in digit:
possible.append(digit)
result.append(digit)
for i in range(len(arr)):
strike = arr[i][1]
ball = arr[i][2]
num = str(arr[i][0])
first = num[0]
second = num[1]
third = num[2]
for j in range(len(possible)):
strike_cnt = 0
ball_cnt = 0
if str(possible[j][0]) == first:
strike_cnt += 1
elif str(possible[j][0]) in num:
ball_cnt += 1
if str(possible[j][1]) == second:
strike_cnt += 1
elif str(possible[j][1]) in num:
ball_cnt += 1
if str(possible[j][2]) == third:
strike_cnt += 1
elif str(possible[j][2]) in num:
ball_cnt += 1
if strike != strike_cnt or ball != ball_cnt:
try:
re_val = possible[j]
result.remove(re_val)
except:
continue
print(len(result))
|
cs |