[백준] 2607번 비슷한 단어

거북이·2023년 4월 6일
0

백준[실버3]

목록 보기
84/92
post-thumbnail

💡문제접근

  • 전에 시도했다가 틀렸던 문제여서 다시 풀어보기 위해 도전했다.
  • 첫 번째 단어에서 한 문자를 더하거나, 빼거나 하나의 문자를 다른 문자로 바꾸어 나머지 입력받은 단어와 구성을 같게 하는 경우 비슷한 단어라고 한다.

💡코드(메모리 : 31256KB, 시간 : 40ms)

import sys
input = sys.stdin.readline

T = int(input())
first_word = list(input().strip())

result = 0
for i in range(T-1):
    copy_word = first_word[:]
    input_word = list(input().strip())
    cnt = 0

    for j in input_word:
        if j in copy_word:
            copy_word.remove(j)
        else:
            cnt += 1
    if cnt < 2 and len(copy_word) <= 1:
        result += 1
print(result)

💡소요시간 : 18m

0개의 댓글