1759번: 암호 만들기
첫째 줄에 두 정수 L, C가 주어진다. (3 ≤ L ≤ C ≤ 15) 다음 줄에는 C개의 문자들이 공백으로 구분되어 주어진다. 주어지는 문자들은 알파벳 소문자이며, 중복되는 것은 없다.
www.acmicpc.net
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
char a[15];
bool check(string &str, int l) {
int m = 0;
for (char x : str) if (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u') m ++;
return m >= 1 && l-m >= 2;
}
void password(int index, int start, int c, int l, string str) {
if (index == l && check(str, l)) {
cout << str << '\n';
return;
}
for (int i = start; i < c; i++) password(index + 1, i + 1, c, l, str + a[i]);
}
int main() {
int L, C; cin >> L >> C;
for (int i = 0; i < C; i++) {
char tmp; cin >> tmp; a[i] = tmp;
}
sort(a, a + C);
password(0, 0, C, L, "");
return 0;
}
'CodingTest > 백준' 카테고리의 다른 글
[JAVA] 백준 - 10814번: 나이순 정렬 | Arrays.sort() (0) | 2023.09.25 |
---|---|
[c++] 백준 - 10971: 외판원 순회2 (0) | 2023.07.30 |
[c++] 백준 - 15649번: N과 M (1) | 재귀함수, string (0) | 2023.07.18 |
[c++] 백준 - 1259번: 팰린드롬수 (0) | 2023.05.31 |
[c++] 백준 - 2798번: 블랙잭 (0) | 2023.05.31 |