공부하고 기록하는, 경제학과 출신 개발자의 노트

프로그래밍/코딩테스트 문제풀이

[Python] 백준 1759. 암호 만들기

inspirit941 2020. 3. 26. 14:14
반응형

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

 

1759번: 암호 만들기

첫째 줄에 두 정수 L, C가 주어진다. (3 ≤ L ≤ C ≤ 15) 다음 줄에는 C개의 문자들이 공백으로 구분되어 주어진다. 주어지는 문자들은 알파벳 소문자이며, 중복되는 것은 없다.

www.acmicpc.net

백준 브루트 포스 문제유형.

 

combinations로 모든 경우의 수를 탐색하면 된다.

 

 

from itertools import combinations
import sys
L, C = map(int, sys.stdin.readline().split())
arr = sys.stdin.readline().split()
arr.sort()
vowel = {'a','e','i','o','u'}
consonant = set(list("abcdefghijklmnopqrstuvwxyz")) - vowel
candidate = combinations(range(len(arr)), L)
for value in candidate:
temp = []
for i in range(L):
temp.append(arr[value[i]])
if len(set(temp) & vowel) >= 1 and len(set(temp) & consonant) >= 2:
print("".join(temp))
반응형