[Python][백준 4659] 비밀번호 발음하기

서윤·2023년 7월 13일

백준

목록 보기
23/23
post-thumbnail

문제

https://www.acmicpc.net/problem/4659

풀이

import sys 

vowel = {'a','e','i','o','u'} #모음 

while (1):
    word = sys.stdin.readline().rstrip()
    if word == 'end':
        break

    list_word = list(word)

    v_exist = 0 # 모음 존재하는지 확인 
    v_cnt = 0 # 모음 3개 연속인지 확인 
    c_cnt = 0 # 자음 3개 연속인지 확인 
    err = 0 # 자음/모음 연속 3개인 경우 1

    for i in range(len(list_word)):
        if i > 0:
            if list_word[i] == list_word[i-1]: #같은 글자가 연속 2번 오는지 확인 
                if list_word[i] != 'e' and list_word[i] != 'o':
                    err = 1
                    break
        if list_word[i] in vowel:
            v_exist = 1
            v_cnt += 1
            c_cnt = 0
            if v_cnt == 3:
                err = 1
                break
        else:
            v_cnt = 0
            c_cnt += 1
            if c_cnt == 3:
                err = 1
                break
    
    if (err!=1) and (v_exist ==1):
        print("<"+ word +"> is acceptable.")
    else:
        print("<"+ word +"> is not acceptable.")
profile
UXUI Designer

0개의 댓글