https://www.acmicpc.net/problem/4659
자음리스트, 모음리스트 생성
조건1: 단어를 입력받고 요소를 하나씩 꺼내서 요소가 모음 리스트에 하나라도 있으면 조건1 통과
조건2: 자음 카운트, 모음 카운트를 만들어서 자음이 나오면 자음 카운트에 + 1을 하고 모음 카운트를 초기화, 모음이 나오면 모음 카운트에 + 1을 하고 자음 카운트를 초기화 하는 식으로 구현.
결국 두 카운트 중 하나라도 3을 넘지 않으면 조건2 통과
조건3: 전 단어의 요소와 현재 단어의 요소가 같고 그 단어의 요소가 e나 o라면 넘어가고 아니라면 조건3 기각
#consonant 자음
#vowel 모음
consonant = ['b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','x','z']
vowel = ['a','e','i','o','u']
while True:
condition = [0,1,1] #조건1, 조건2, 조건3
con_count = 0
vo_count = 0
same_count = 0
temp_word = '!'
word = input()
if word == 'end':
exit()
for i in range(len(word)): #조건1, 조건2, 조건3
#print(temp_word)
if temp_word == word[i]:
if word[i] == 'e' or word[i] == 'o':
continue
else:
condition[2] = 0
if word[i] in consonant: #자음
con_count += 1
vo_count = 0
if word[i] in vowel: #모음
condition[0] = 1
vo_count += 1
con_count = 0
if vo_count >=3 or con_count >=3:
condition[1] = 0
temp_word = word[i]
#print(f'조건1:{condition[0]}, 조건2:{condition[1]}, 조건3: {condition[2]}')
if condition[0] == 1 and condition[1] == 1 and condition[2] == 1:
print(f'<{word}> is acceptable.')
else:
print(f'<{word}> is not acceptable.')
'백준' 카테고리의 다른 글
[백준] 2034번: 반음(파이썬) (0) | 2024.09.27 |
---|---|
[백준] 10384번: 팬그램(파이썬) (2) | 2024.09.27 |
[백준] 17219번: 비밀번호 찾기 (파이썬) (0) | 2023.07.24 |
[백준] 11723번 : 집합 (파이썬) (0) | 2023.07.21 |
[백준] 11047번 동전 0 (파이썬) (1) | 2023.07.19 |