하루일문

[백준] 11478번 서로다른 문자열 개수(파이썬) 본문

algorithm/baekjoon

[백준] 11478번 서로다른 문자열 개수(파이썬)

support_u 2023. 3. 9. 21:19

문제

 

11478번: 서로 다른 부분 문자열의 개수

첫째 줄에 문자열 S가 주어진다. S는 알파벳 소문자로만 이루어져 있고, 길이는 1,000 이하이다.

www.acmicpc.net

코드

 

import sys
input = sys.stdin.readline
s = input().strip()
dic = {} 

for i in range(len(s)):
    for j in range(i+1, len(s)+1):
        if s[i:j] not in dic:
            dic[s[i:j]] = 1
        else:
            dic[s[i:j]] += 1

print(len(dic))

 

해설

 

문자를 다 받아서 딕셔너리에 넣어서 딕셔너리 개수를 구했다.