[백준4659_파이썬(python)] - 비밀번호 발음하기

경이·2023년 5월 29일
0

🔴 문제

비밀번호 발음하기


🟡 Sol

def check(pw):
  C = "aeiou"
  V = "bcdfghjklmnpqrstvwxyz"
  if "a" not in pw and "e" not in pw and "i" not in pw and "o" not in pw and "u" not in pw:
        return False
  prev = pw[0]
  stack = 0
  for i in pw[1:]:
      if prev!="e" and prev!="o" and prev == i:
          return False
      if (prev in C and i in C) or (prev in V and i in V):
          stack += 1
      else:
          stack = 0
      if stack >= 2:
          return False
      prev = i
  return True

while True:
    pw = input()
    if pw == "end":        
        break
    if check(pw):
        print("<{}> is acceptable.".format(pw))
    else:
        print("<{}> is not acceptable.".format(pw))

🟢 풀이

무한반복 안에서 함수 호출 결과에 따라 출력문을 다르게 해줬다.
check()함수에서는 문제에서 주어진 조건을 사용했다.
정규표현식을 사용하면 깔끔할듯


🔵 Ref

profile
이사중입니다!🌟https://velog.io/@devkyoung2

0개의 댓글

관련 채용 정보