Jae-Kyung Cho LLM Developers who was a Robotics engineer

Baekjoon-1141-접두사

N = int(input())
word_list = []
for _ in range(N):
    new_word = input().strip()
    if len(word_list) == 0:
        word_list.append(new_word)
        continue

    
    for word in word_list:
        is_same = True
        if len(word) > len(new_word):
            for i in range(len(new_word)):
                if word[i]!=new_word[i]:
                    is_same = False
                    break   
            if is_same:
                break
        else:
            for i in range(len(word)):
                if word[i]!=new_word[i]:
                    is_same = False
                    break
            if is_same:
                word_list.remove(word)
                word_list.append(new_word)
                break
    if not is_same:
        word_list.append(new_word)

print(len(word_list))
Comments