using
System;
using
System.Collections.Generic;
class
Node {
public
string
data_str;
public
Node left;
public
Node right;
public
Node(
string
data_str)
{
this
.data_str = data_str;
left = right =
null
;
}
public
string
get_data_str() {
return
data_str; }
}
class
Program {
static
Node create_tree(
int
data,
string
p_str,
List<
int
> arr)
{
if
(data > 26) {
return
null
;
}
string
data_to_str = p_str + (
char
)(
'a'
+ data - 1);
Node root =
new
Node(data_to_str);
if
(arr.Count != 0) {
data = arr[0];
List<
int
> new_arr
= arr.GetRange(1, arr.Count - 1);
root.left
= create_tree(data, data_to_str, new_arr);
if
(arr.Count > 1) {
data = arr[0] * 10 + arr[1];
new_arr = arr.GetRange(2, arr.Count - 2);
root.right = create_tree(data, data_to_str,
new_arr);
}
}
return
root;
}
static
void
print_leaf(Node root)
{
if
(root ==
null
) {
return
;
}
if
(root.left ==
null
&& root.right ==
null
) {
Console.Write(root.get_data_str() +
" "
);
}
print_leaf(root.left);
print_leaf(root.right);
}
static
void
printAllInterpretations(List<
int
> arr)
{
Node root = create_tree(0,
""
, arr);
print_leaf(root);
Console.WriteLine();
}
static
void
Main(
string
[] args)
{
List<
string
> alphabet =
new
List<
string
>{
""
,
"a"
,
"b"
,
"c"
,
"d"
,
"e"
,
"f"
,
"g"
,
"h"
,
"i"
,
"j"
,
"k"
,
"l"
,
"m"
,
"n"
,
"o"
,
"p"
,
"q"
,
"r"
,
"s"
,
"t"
,
"u"
,
"v"
,
"w"
,
"x"
,
"y"
,
"z"
};
List<
int
> arr =
new
List<
int
>{ 1, 1, 3, 4 };
printAllInterpretations(arr);
arr =
new
List<
int
>{ 1, 1, 1 };
printAllInterpretations(arr);
arr =
new
List<
int
>{ 2, 6 };
printAllInterpretations(arr);
arr =
new
List<
int
>{ 1, 2 };
printAllInterpretations(arr);
arr =
new
List<
int
>{ 1, 0 };
printAllInterpretations(arr);
arr =
new
List<
int
>{};
printAllInterpretations(arr);
arr =
new
List<
int
>{ 1, 2, 2, 1 };
printAllInterpretations(arr);
}
}