-
[1411] 비슷한 단어 (Python)[Python] 알고리즘/Silver 2022. 3. 1. 19:48
[문제]
https://www.acmicpc.net/problem/1411
알고리즘 분류는 구현, 문자열, 브루트포스 알고리즘 입니다.
처음 나오는 문자를 1, 그 다음 나오는 문자를 2, ... 로 바꾸어서 풀었습니다.
[코드]
import sys N = int(sys.stdin.readline()) li = list() for i in range(N): word = sys.stdin.readline().rstrip() k = 1 s = "" dt = dict() for j in range(26): dt[chr(j + 97)] = -1; dt[word[0]] = 1 for j in range(len(word)): if j != 0 and dt[word[j]] == -1: k += 1 dt[word[j]] = k s += str(k) else: s += str(dt[word[j]]) li.append(s) res = 0 for i in range(N - 1): for j in range(i + 1, N): if li[i] == li[j]: res += 1 print(res)
'[Python] 알고리즘 > Silver' 카테고리의 다른 글
[1535] 안녕 (Python) (0) 2022.03.21 [1138] 한 줄로 서기 (Python) (0) 2022.03.18 [1972] 놀라운 문자열 (Python) (0) 2021.12.23 [1544] 사이클 단어 (Python) (0) 2021.12.22 [1021] 회전하는 큐 (Python) (0) 2021.12.21