문제 : https://www.acmicpc.net/problem/1759
코드
from itertools import combinations
L, C = map(int, input().split())
alpabet = sorted(list(input().split()))
vowel = {'a', 'e', 'i', 'o', 'u'}
result = []
for pw in combinations(alpabet, L):
count_vowels = sum(1 for i in pw if i in vowel)
if count_vowels >= 1 and L - count_vowels >= 2:
result.append(''.join(pw))
for pw in result:
print(pw)
서로 다른 L개의 암호를 구성하는데 최소 한 개의 모음과 최소 두 개의 자음으로 구성해야 하는 문제이다.
최소한의 모음은 count_vowels >= 1로, 최소한의 자음은 L - count_vowels >= 2 코드로 조건을 걸어 구할 수 있다.
'코딩테스트 > 백준 (python)' 카테고리의 다른 글
백준 / 2178번 / 미로 탐색 / python 파이썬 (0) | 2024.09.20 |
---|---|
백준 / 1149번 / RGB거리 / python 파이썬 (0) | 2024.09.19 |
백준 / 1107번 / 리모컨 / python 파이썬 (0) | 2024.09.12 |
백준 / 28278번 / 스택 2 / python 파이썬 (0) | 2024.09.12 |
백준 / 1629번 / 곱셈 / python 파이썬 (0) | 2024.09.09 |