티끌모아 태산

[백 준/구현] 4659: 비밀번호 발음하기 본문

백준 문제

[백 준/구현] 4659: 비밀번호 발음하기

goldpig 2024. 1. 10. 14:29
728x90

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

 

4659번: 비밀번호 발음하기

좋은 패스워드를 만드는것은 어려운 일이다. 대부분의 사용자들은 buddy처럼 발음하기 좋고 기억하기 쉬운 패스워드를 원하나, 이런 패스워드들은 보안의 문제가 발생한다. 어떤 사이트들은 xvtp

www.acmicpc.net

핵심 아이디어

  • 문제에서 주어진 조건만 만족시키면 풀 수 있다.

풀이 (1)

# 모음 받아오기
lst = ['a','e','i','o','u']

#입력은 여러개의 테스트 케이스로 이루어진다.
while True:
	# 문자열 입력받기
	s = input()
	# end 이면 반환
	if s == 'end':
		break
	# 1. 모음 하나를 반드시 포함하여야한다.
	# 모음 수 카운트 변수
	cnt = 0
	for i in lst:
		if i in s:
			cnt += 1
	if cnt < 1:
		print(f'<{s}> is not acceptable.')
		continue
	# 2. 모음이 3개 혹은 자음이 3개 연속으로 오면 안된다.
	x=y=0
	for i in range(len(s) - 2):
		# 모음 연속해서 3개 나오는 경우
		if s[i] in lst and s[i+1] in lst and s[i+2] in lst:
			x = 1
		# 자음 연속해서 3개 나오는 경우
		elif (s[i] not in lst and s[i+1] not in lst and s[i+2] not in lst):
			x = 1
	if x == 1:
		print(f'<{s}> is not acceptable.')
		continue
	# 3. 같은 글자가 연속적으로 두번 오면 안되나, ee와 oo는 허용한다.
	for i in range(len(s) - 1):
		if s[i] == s[i+1]:
			if s[i] == 'e' or s[i] == 'o':
				continue
			else:
				y = 1
	if y == 1:
		print(f'<{s}> is not acceptable.')
		continue
	# 다 통과하면 허용
	print(f'<{s}> is acceptable.')

풀이 (2)

# 모음 받아오기
lst = ['a','e','i','o','u']

#입력은 여러개의 테스트 케이스로 이루어진다.
while True:
	# 문자열 입력받기
	s = input()
	# end 이면 반환
	if s == 'end':
		break
	# 1. 모음 하나를 반드시 포함하여야한다.
	if not any(i in s for i in lst):
		print(f'<{s}> is not acceptable.')
		continue
	# 2. 모음이 3개 혹은 자음이 3개 연속으로 오면 안된다.
	x=y=0
	for i in range(len(s) - 2):
		# 모음 연속해서 3개 나오는 경우
		if s[i] in lst and s[i+1] in lst and s[i+2] in lst:
			x = 1
		# 자음 연속해서 3개 나오는 경우
		elif (s[i] not in lst and s[i+1] not in lst and s[i+2] not in lst):
			x = 1
	if x == 1:
		print(f'<{s}> is not acceptable.')
		continue
	# 3. 같은 글자가 연속적으로 두번 오면 안되나, ee와 oo는 허용한다.
	for i in range(len(s) - 1):
		if s[i] == s[i+1]:
			if s[i] == 'e' or s[i] == 'o':
				continue
			else:
				y = 1
	if y == 1:
		print(f'<{s}> is not acceptable.')
		continue
	# 다 통과하면 허용
	print(f'<{s}> is acceptable.')
728x90