https://www.acmicpc.net/problem/1759
1759번: 암호 만들기
첫째 줄에 두 정수 L, C가 주어진다. (3 ≤ L ≤ C ≤ 15) 다음 줄에는 C개의 문자들이 공백으로 구분되어 주어진다. 주어지는 문자들은 알파벳 소문자이며, 중복되는 것은 없다.
www.acmicpc.net
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool check(string& password) {
int ja = 0;
int mo = 0;
for (char x : password) {
if (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u') {
mo += 1;
}
else {
ja += 1;
}
}
return ja >= 2 && mo >= 1;
}
void go(int n, vector<char>& alpha, string password, int i) {
if (password.length() == n) {
if (check(password)) {
cout << password << '\n';
}
return;
}
if (i == alpha.size()) return;
go(n, alpha, password + alpha[i], i + 1);
go(n, alpha, password, i + 1);
}
int main() {
int n, m;
cin >> n >> m;
vector<char> a(m);
for (int i = 0; i < m; i++) {
cin >> a[i];
}
sort(a.begin(), a.end());
go(n, a, "", 0);
return 0;
}
|
cs |
'브루트 포스 > 브루트포스(재귀)' 카테고리의 다른 글
맞춰봐 (백트래킹) (0) | 2023.03.01 |
---|---|
부등호 (백트래킹) (0) | 2023.02.28 |
스타트와 링크 (0) | 2023.02.28 |
퇴사 (0) | 2023.02.27 |
1, 2, 3 더하기 (0) | 2023.02.27 |