백준 1759번 암호만들기

tiki·2021년 5월 20일
0

백준

목록 보기
9/30

백준 1759번 암호만들기를 풀어보겠습니다.

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

파이썬 코드

from itertools import combinations

L, C = map(int, input().split())
li = list(map(str, input().split()))

comb = list(combinations(li, L))
sorted_string = []

for tup in comb:
  sorted_combs.append(sorted(tup))

for string in sorted(sorted_combs):
  vowels = 0
  consonants =0
  for alphabet in string:
    if alphabet in 'aeiou':
      vowels += 1
    else:
      consonants += 1
  
  if vowels >= 1 and consonants >= 2:
    print("".join(string))

조건 & 구현

  • 암호는 3글자 이상이다.
  • 암호는 모음 1개, 자음 2개 이상을 꼭 포함해야한다.
  • 가능한 암호는 알파벳 순서대로 구성되어야 한다.
  • 가능한 암호를 알파벳 순서대로 나열한다.

다음 조건을 만족하면서 구현하면 되는 문제이다.

가능한 알파벳 조합을 combinations 을 이용하여 나타내고

그 알파벳 조합을 다시 알파벳 순서대로 sorted 하여 다시 리스트에 넣어준다!

이 리스트를 모음과 자음 갯수를 만족하는 조합들만 print 해준다.

profile
하루하루 조금씩 발전하려는 개발자 입니다.

0개의 댓글

관련 채용 정보