이거 때문에 list 함부로 remove 하면 안된다
a = [1,2,3,4,5]
b = [2,3]
for i in a:
if i in b:
a.remove(i)
print(a)
# 원했던 답 : [1,4,5]
# 출력되는 답 : [1,3,4,5]
#이렇게 했으면 된다 123 ~ 987 중복 안되는 리스트 만들어준다
a = [i for i in range(1, 10)]
numbers = list(permutations(a,3))
# 이렇게 하면 알아서 자리수 나눠준다
guess = list(str(guess))
완전 탐색 방식으로 싹다 찾아보는 식의 문제풀이 방법이다. 처음 시험때 이렇게 일일히 다 뒤져가면서 푼다는걸 생각 못했었지만 이번엔 기억이 났다. 그래도 다시 풀때 어떻게 제거해 나가지 고민이 좀 들었지만 그냥 조건 안맞으면 싹다 제거하면 됬었다.
그래도 풀이방식의 로직은 나름 쉬운 편이라 별 두개 준다.
import sys
sys.stdin = open('input.txt')
input = sys.stdin.readline
N = int(input())
numbers = [True for i in range(1000)]
# 같은 수 있는거 빼기
for i in range(1000):
first = i // 100
second = (i % 100) // 10
third = i % 10
if first == 0 or second == 0 or third == 0:
numbers[i] = False
elif first == second or second == third or third == first:
numbers[i] = False
# 스트라이크 : 동일한 자리에 있으면, 볼: 숫자는 같은데 다른 자리에 있으면
for _ in range(N):
num, strike, ball = map(int, input().split())
input_first = num // 100
input_second = (num % 100) // 10
input_third = num % 10
input_list = [input_first, input_second, input_third]
for j in range(len(numbers)):
if numbers[j] == False:
continue
comp_first = j // 100
comp_second = (j % 100) // 10
comp_third = j % 10
comp_list = [comp_first, comp_second, comp_third]
temp_strike = 0
temp_ball = 0
for i in range(3):
if comp_list[i] == input_list[i]:
temp_strike += 1
elif comp_list[i] in input_list:
temp_ball += 1
if temp_strike != strike or temp_ball != ball:
numbers[j] = False
for i in range(len(numbers)):
if numbers[i]:
print(i)
# print(sum(numbers))