[백준/Python] 1316 그룹 단어 체커

재활용병·2024년 1월 10일
0

코딩 테스트

목록 보기
19/157

[백준/Python] 1316 그룹 단어 체커


풀이 코드 및 설명

import sys
def is_group_word(word):
    alphabet_seen = [False] * 26

    for i in range(len(word)):
        # 현재 문자가 이전 문자와 다르면
        if i > 0 and word[i] != word[i - 1]:
            # 현재 문자가 이미 등장한 문자라면 그룹 단어가 아님
            if alphabet_seen[ord(word[i - 1]) - ord('a')]:
                return False
            alphabet_seen[ord(word[i - 1]) - ord('a')] = True
    
    return True


N = int(sys.stdin.readline().rstrip())

group_word_count = 0

for _ in range(N):
    word = sys.stdin.readline().rstrip()
    if is_group_word(word):
        group_word_count += 1

print(group_word_count)
profile
코딩 말고 개발

0개의 댓글

관련 채용 정보