Coding Test/BaekJoon_Python
백준 1759 <암호 만들기> Python
JunOnJuly
2024. 11. 11. 12:50
728x90
https://www.acmicpc.net/problem/1759
조합 문제입니다.
문자를 정렬 후 조합시키면 조합된 문자열이 나오니 이들 중 조건에 맞는 것을 필터링하면 됩니다.
import sys
from itertools import combinations
input = sys.stdin.readline
def solution(L, C, chr):
# 조합
for comb in combinations(chr, L):
# 한 개의 모음과 두 개의 자음
m = 0
j = 0
for c in comb:
if c in 'aeiou':
m += 1
else:
j += 1
if m and j >= 2:
print(''.join(comb))
# 입력
L, C = map(int, input().strip().split())
chr = ''.join(sorted(input().strip().split()))
solution(L, C, chr)
728x90