-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1759.cpp
71 lines (62 loc) · 1.05 KB
/
1759.cpp
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// 1759. 암호 만들기
// 2019.05.18
// 백트래킹
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
vector<char> alpa;
int l, c;
char ans[16];
int consonant; // 자음의 개수
int vowel; // 모음의 개수
// 재귀로 모든 암호 만들기
void go(int start, int cnt)
{
if (cnt == l)
{
consonant = 0;
vowel = 0;
for (int i = 0; i < l; i++)
{
if (ans[i] == 'a' || ans[i] == 'e' || ans[i] == 'i' || ans[i] == 'o' || ans[i] == 'u')
{
vowel++;
}
else
{
consonant++;
}
}
// 최소 한 개의 모음과 최소 두 개의 자음으로 구성되어있다면 출력
if (vowel >= 1 && consonant >= 2)
{
for (int i = 0; i < l; i++)
{
cout << ans[i];
}
cout << endl;
}
return;
}
// 재귀 돌리기
for (int i = start; i < c; i++)
{
ans[cnt] = alpa[i];
go(i + 1, cnt + 1);
}
}
int main()
{
cin >> l >> c;
for (int i = 0; i < c; i++)
{
char tmp;
cin >> tmp;
alpa.push_back(tmp);
}
// 오름차순 정렬
sort(alpa.begin(), alpa.end());
go(0, 0);
return 0;
}