[python] 암호 만들기

루송·2022년 10월 7일
0

python

목록 보기
1/7
post-thumbnail

암호만들기 예제

입력조건

  • 첫째 줄에 두 정수 L, C가 주어짐 (3 <= L <= C <= 15)
    -> map(int, input().split(' ')) 활용
  • 다음 줄에는 C개의 문자들이 주어지며 공백으로 구분
    input().split('') 활용
  • 주어지는 문자들은 알파벳 소문자이며, 중복은 없음
    from itertools import combinations 이용

출력조건

  • 각 줄에 하나씩, 사전식으로 가능성 잇는 암호를 모두 출력
    sort() 이용하여 정렬

코드

from itertools import combinations

vowels = ('a', 'e', 'i', 'o', 'u')
l, c = map(int, input().split(' '))

array = input().split(' ')
array.sort()

for password in combinations(array, l):
    count = 0
    for i in password:
        if i in vowels:
            count += 1
    if count >= 1 and count <= l - 2:
        print(''.join(password))

입출력 결과

0개의 댓글

관련 채용 정보