许诺 • 1天前
using namespace std;
int L, C; vector letters; vector password; int vowel_count, consonant_count; int output_count = 0; bool is_vowel(char c) {
return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
} void generate(int index) {
if (output_count >= 25000) return;
if (password.size() == L) {
if (vowel_count >= 1 && consonant_count >= 2) {
for (char c : password) {
cout << c;
}
cout << endl;
output_count++;
}
return;
}
if (index >= C) return;
char current = letters[index];
password.push_back(current);
if (is_vowel(current)) {
vowel_count++;
} else {
consonant_count++;
}
generate(index + 1);
password.pop_back();
if (is_vowel(current)) {
vowel_count--;
} else {
consonant_count--;
}
generate(index + 1);
}
int main() {
cin >> L >> C;
letters.resize(C);
for (int i = 0; i < C; i++) {
cin >> letters[i];
}
sort(letters.begin(), letters.end());
vowel_count = 0;
consonant_count = 0;
output_count = 0;
generate(0);
return 0;
}
评论:
请先登录,才能进行评论