import
java.util.ArrayList;
import
java.util.HashMap;
import
java.util.List;
import
java.util.Map;
public
class
Main {
public
static
List<String> findCombinations(List<Integer> input,
List<Character>[] table) {
List<String> out =
new
ArrayList<>();
List<String> temp =
new
ArrayList<>();
Map<Integer, Integer> mp =
new
HashMap<>();
int
index =
0
;
for
(
int
d : input) {
if
(!mp.containsKey(d))
mp.put(d, index);
temp.clear();
for
(
int
i =
0
; i < table[d -
1
].size(); i++) {
if
(index ==
0
) {
out.add(Character.toString(table[d -
1
].get(i)));
}
if
(index >
0
) {
for
(String str : out) {
String s = Character.toString(table[d -
1
].get(i));
if
(mp.get(d) != index)
s = Character.toString(str.charAt(mp.get(d)));
str = str + s;
temp.add(str);
}
if
(mp.get(d) != index)
break
;
}
}
if
(index >
0
)
out =
new
ArrayList<>(temp);
index++;
}
return
out;
}
public
static
void
main(String[] args) {
List<Character>[] table =
new
ArrayList[] {
new
ArrayList<>(List.of(
'A'
,
'B'
,
'C'
)),
new
ArrayList<>(List.of(
'D'
,
'E'
,
'F'
)),
new
ArrayList<>(List.of(
'G'
,
'H'
,
'I'
)),
new
ArrayList<>(List.of(
'J'
,
'K'
,
'L'
)),
new
ArrayList<>(List.of(
'M'
,
'N'
,
'O'
)),
new
ArrayList<>(List.of(
'P'
,
'Q'
,
'R'
)),
new
ArrayList<>(List.of(
'S'
,
'T'
,
'U'
)),
new
ArrayList<>(List.of(
'V'
,
'W'
,
'X'
)),
new
ArrayList<>(List.of(
'Y'
,
'Z'
))
};
List<Integer> input = List.of(
1
,
2
,
1
);
List<String> out = findCombinations(input, table);
for
(String str : out)
System.out.print(str +
" "
);
}
}