백준 18129번: 이상한 암호코드 #Python

ColorlessDia·2024년 12월 17일

algorithm/baekjoon

목록 보기
394/836
S, K = input().split()
S = S.lower()
K = int(K)

string_range_list = []

s = 0
e = 0

while True:

    if s == e:
        e += 1
    
    if len(S) <= e:
        string_range_list.append(S[s:e])
        break
    
    if S[s] == S[e]:
        e += 1
        continue
    
    string_range_list.append(S[s:e])

    s = e
    e = s + 1

alphabat_count = dict()

ciphertext = ''

for string_range in string_range_list:
    alphabat = string_range[0]

    if alphabat in alphabat_count:
        continue
    
    alphabat_count[alphabat] = 1
    
    if K <= len(string_range):
        ciphertext += '1'
    else:
        ciphertext += '0'

print(ciphertext)

0개의 댓글