[Python] 알고리즘/Gold
[1759] 암호 만들기 (Python)
-Becca-
2022. 5. 31. 17:38
[문제]
https://www.acmicpc.net/problem/1759
1759번: 암호 만들기
첫째 줄에 두 정수 L, C가 주어진다. (3 ≤ L ≤ C ≤ 15) 다음 줄에는 C개의 문자들이 공백으로 구분되어 주어진다. 주어지는 문자들은 알파벳 소문자이며, 중복되는 것은 없다.
www.acmicpc.net
알고리즘 분류는 수학, 브루트포스 알고리즘, 조합론, 백트래킹 입니다.
Python의 combinations(조합)을 사용한 후, 모음과 자음의 개수를 이용하여 답을 도출해냈습니다.
[코드]
import sys
from itertools import combinations
L, C = map(int, sys.stdin.readline().split())
word = sys.stdin.readline().split()
vowel = list()
cons = list()
for i in word:
if i in ['a', 'e', 'i', 'o', 'u']:
vowel.append(i)
else:
cons.append(i)
comb = list(combinations(word, L))
res = list()
for i in comb:
vcnt = 0
ccnt = 0
for j in i:
if j in vowel:
vcnt += 1
else:
ccnt += 1
if vcnt >= 1 and ccnt >= 2:
t = tuple(sorted(i))
res.append("".join(t))
res = sorted(set(res))
for i in res:
print(i)