题目大意:
mxy 正要经过新世界的大门。
现在有很多人在门口排队,每个人将会被发到一个有效的通行密码作为门票。一个有
效的密码由 L(3 <= L <= 15)个小写字母(‘a’…‘z’)组成,至少有一个元音(‘a’, ‘e’, ‘i’,
‘o’ 或 ‘u’)和两个辅音(除去元音以外的音节),并且是按字母表顺序出现的(例如,‘abc’
是有效的,而’bac’不是) 。
mxy 想要知道今天的有效密码是什么。
现在给定一个期望长度 L 和 C(1 <= C <= 26)个小写字母,写一个程序,输出所有的
长度为 L、能由这给定的 C 个字母组成的有效密码。密码必须按字母表顺序打印出来,一行
一个。
解题思路:
数据很小,直接暴搜
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int C, L, sum;
char a[30], c[30];
void dfs(int now, int num) {
if (sum == 25000) return;
if (num == L) {
int yy = 0, fy = 0;
for (int i = 1; i <= L; ++i) {
if (a[i] == 'a' || a[i] == 'e' || a[i] == 'i' || a[i] == 'o' || a[i] == 'u')
++yy; else ++fy;
}
if (yy && fy > 1) {
for (int i = 1; i <= L; ++i)
putchar(a[i]);
putchar('\n');
++sum;
}
return;
}
for (int i = now + 1; i <= C; ++i) {
a[num+1] = c[i];
dfs(i, num + 1);
}
}
int main() {
scanf("%d %d", &L, &C);
for (int i = 1; i <= C; ++i)
cin >> c[i];
sort(c+1, c+C+1);
int n = C - L + 1;
for (int i = 1; i <= n; ++i) {
a[1] = c[i];
dfs(i, 1);
}
}