static void Tree(int[] hs)
{
//int[] hs = { 2, 3, 4, 1, 2, 2, 3, 4, 3, 3, 4, 5, 5, 2, 4, 4 };
int k = 0;
int h;
int s = 5;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hs.Length; i++)
{
h = hs[i];
if (h < s) s = h;
if (i > 0) k = hs[i - 1];
if (h <= k)
{
sb.Remove(sb.Length - 1, 1);
sb.Append("|");
for (int a = 0; a < h - s; a++)
sb.Append("-");
}
sb.Append(h.ToString() + ", ");
}
string[] strs = sb.ToString().Split('|');
string[] sts;
int h1 = 0;
string ht = "";
sb = new StringBuilder();
for (int b = 0; b < strs.Length; b++)
{
sts = strs[b].Split(',');
for (int c = 0; c < sts.Length - 1; c++)
{
if (c == 0)
{
if (sts[c].StartsWith("-"))
{
string ht2 = "";
int idx = Math.Min(sts[c].Length - 1, ht.Split('.').Length - 1);
int d = int.Parse(ht.Split('.')[idx]) + 1;
for (int e = 0; e < idx; e++)
{
ht2 += ht.Split('.')[e] + ".";
}
ht = ht2 + d.ToString();
}
else
{
h1++;
ht = h1.ToString();
}
}
else ht += ".1";
for (int l = 0; l < ht.Split('.').Length; l++)
sb.Append("-");
sb.Append(ht);
sb.Append("/n");
}
}
Console.Write(sb.ToString());
}
作者:朱会震