문제 링크

문제 요약

  • 주어지는 문자열의 PrefixSuffix 문자열 중, 길이가 같으면서 모음의 개수가 같은 경우의 수를 구하면 됩니다.
  • 단, PrefixSuffix 문자열 중 모음의 개수는 0보다 커야 합니다.

풀이

  • 앞, 뒤를 동시에 확인하면서 조건을 만족하면 개수를 세면 됩니다.

정답 코드

inp = input()
ii = lambda : int(inp())
 
n = ii()
s = inp().lower()
 
vowel = "aeiou"
 
prefix_vowel_count = 0
suffix_vowel_count = 0
ans = 0
 
for i in range(n):
	if s[i] in vowel:
		prefix_vowel_count += 1
	
	if s[n - i - 1] in vowel:
		suffix_vowel_count += 1
 
	if prefix_vowel_count == suffix_vowel_count and prefix_vowel_count > 0:
		ans += 1
 
print(ans)

연관 페이지

참고 문헌 / 사이트