백준 2503 숫자야구 - python
너무 어렵지 않은 완전 탐색 문제집 1번문제 !!
문제풀이
- 어릴 때 많이했던 숫자야구문제
- 각 자리수별로 탐색하면서 주어진 숫자와 카운트가 같지 않은 경우를 모두 지워준다
- 다 풀고나서 itertools permutation을 쓰면 좋았겠다라는 생각이 문득….
code
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
49
def check(one, two, three, s, b):
for i in range(100,1000):
ns, nb = 0, 0
if(res[i]):
n_one = int(i/100)
n_two = int((i%100)/10)
n_three = int((i%100)%10)
if(one == n_one):
ns += 1
if(two == n_two):
ns += 1
if(three == n_three):
ns += 1
if(one != n_one and (one == n_two or one == n_three)):
nb += 1
if(two != n_two and (two == n_one or two == n_three)):
nb += 1
if(three != n_three and (three == n_one or three == n_two)):
nb += 1
if(ns != s or nb != b):
res[i] = False
N = int(input())
res = [True for i in range(1000)]
for i in range(100,1000):
one = int(i/100)
two = int((i%100)/10)
three = int((i%100)%10)
if(one == two or two == three or three == one):
res[i] = False
if(one == 0 or two == 0 or three == 0):
res[i] = False
for n in range(N):
num, s, b = map(int, input().split())
num = str(num)
one, two, three = int(num[0]),int(num[1]),int(num[2])
check(one, two, three, s, b)
cnt = 0
for i in range(100,1000):
if(res[i]):
cnt += 1
print(cnt)