happy coding

[level 1] 옹알이 (2) 본문

coding study/programmars

[level 1] 옹알이 (2)

yeoonii 2024. 7. 2. 01:34

문제 설명

머쓱이는 태어난 지 11개월 된 조카를 돌보고 있습니다. 조카는 아직 "aya", "ye", "woo", "ma" 네 가지 발음과 네 가지 발음을 조합해서 만들 수 있는 발음밖에 하지 못하고 연속해서 같은 발음을 하는 것을 어려워합니다. 문자열 배열 babbling이 매개변수로 주어질 때, 머쓱이의 조카가 발음할 수 있는 단어의 개수를 return하도록 solution 함수를 완성해주세요.


제한사항
  • 1 ≤ babbling의 길이 ≤ 100
  • 1 ≤ babbling[i]의 길이 ≤ 30
  • 문자열은 알파벳 소문자로만 이루어져 있습니다.

내 풀이

def solution(babbling):
    ans = 0
    arr = ["aya", "ye", "woo", "ma"]
    
    for i in babbling:
        for j in arr:
            if j+j in i:
                break
            else:
                i = i.replace(j, ' ')
        if len(i.strip()) == 0:
                ans += 1
    
    return ans

 

다른 풀이

def solution(babbling):
    answer = 0
    for i in babbling:
        for j in ['aya','ye','woo','ma']:
            if j*2 not in i:
                i=i.replace(j,' ')
        if len(i.strip())==0:
            answer +=1
    return answer
def solution(babbling):
    count = 0

    for b in babbling:
        if "ayaaya" in b or "yeye" in b or "woowoo" in b or "mama" in b:
            continue    
        if not b.replace("aya", " ").replace("ye", " ").replace("woo", " ").replace("ma", " ").replace(" ", ""):
            count += 1

    return count

 

'coding study > programmars' 카테고리의 다른 글

[level 1] 소수 찾기  (0) 2024.07.02
[level 1] 소수 만들기  (0) 2024.07.01
[level 1] 과일 장수  (0) 2024.07.01
[level 1] 푸드 파이트 대회  (0) 2024.07.01
[level 1] 모의고사  (0) 2024.07.01
Comments