File tree Expand file tree Collapse file tree 1 file changed +60
-0
lines changed
Expand file tree Collapse file tree 1 file changed +60
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+ import java.util.* ;
4+
5+ public class Main {
6+ static int l, c;
7+ static char [] chars;
8+ static char [] selected;
9+ static StringBuilder sb = new StringBuilder ();
10+
11+ public static void main (String [] args ) throws Exception {
12+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
13+ StringTokenizer st = new StringTokenizer (br. readLine());
14+
15+ l = Integer . parseInt(st. nextToken());
16+ c = Integer . parseInt(st. nextToken());
17+
18+ chars = new char [c];
19+ st = new StringTokenizer (br. readLine());
20+ for (int i = 0 ; i < c; i++ ) {
21+ chars[i] = st. nextToken(). charAt(0 );
22+ }
23+
24+ Arrays . sort(chars);
25+
26+ selected = new char [l];
27+
28+ dfs(0 , 0 , 0 , 0 );
29+
30+ System . out. print(sb);
31+ }
32+
33+ static void dfs (int idx , int depth , int vowel , int consonant ) {
34+ if (depth == l) {
35+ if (vowel >= 1 && consonant >= 2 ) {
36+ sb. append(selected). append(' \n ' );
37+ }
38+ return ;
39+ }
40+
41+ if (idx == c) {
42+ return ;
43+ }
44+
45+ char ch = chars[idx];
46+ selected[depth] = ch;
47+ if (isVowel(ch)) {
48+ dfs(idx + 1 , depth + 1 , vowel+ 1 , consonant);
49+ } else {
50+ dfs(idx + 1 , depth + 1 , vowel, consonant + 1 );
51+ }
52+
53+ dfs(idx + 1 , depth, vowel, consonant);
54+ }
55+
56+ static boolean isVowel (char c ) {
57+ return c == ' a' || c == ' e' || c == ' i' || c == ' o' || c == ' u' ;
58+ }
59+ }
60+ ```
You can’t perform that action at this time.
0 commit comments