반응형
https://www.acmicpc.net/problem/1759
1759번: 암호 만들기
첫째 줄에 두 정수 L, C가 주어진다. (3 ≤ L ≤ C ≤ 15) 다음 줄에는 C개의 문자들이 공백으로 구분되어 주어진다. 주어지는 문자들은 알파벳 소문자이며, 중복되는 것은 없다.
www.acmicpc.net

백준 브루트 포스 문제유형.
combinations로 모든 경우의 수를 탐색하면 된다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
반응형
'프로그래밍 > 코딩테스트 문제풀이' 카테고리의 다른 글
[Python] 프로그래머스. 2019 카카오 겨울 인턴 recruit - 크레인 인형뽑기 게임 (Level 2) (0) | 2020.04.01 |
---|---|
[Python] 백준 2178. 미로 탐색 (0) | 2020.03.31 |
[Python] 프로그래머스. 2019 카카오 recruit - 무지의 먹방 라이브 (Level 3) (0) | 2020.03.25 |
[Python] 프로그래머스. 2018 카카오 recruit - 캐시 (Level 2) (0) | 2020.03.24 |
[Python] 백준 16236. 아기 상어 (0) | 2020.03.23 |