7,765
社区成员
发帖
与我相关
我的任务
分享
int[] hs = { 2, 3, 4, 1, 2, 2, 3, 4, 3, 3, 4, 5 };
//int[] hs = { 2, 5, 8, 3, 6, 9 };
int[] ls = new int[hs.Length]; // 每一位的长度
ls[0] = 1;
for (int i = 1; i < hs.Length; i++)
{
switch (Math.Sign(hs[i] - hs[i - 1]))
{
case 0: // 相等
ls[i] = ls[i - 1];
break;
case +1: // 大于
ls[i] = ls[i - 1] + 1;
break;
case -1: // 小于
for (int j = i - 1; j >= 0; j--)
{
if (hs[i] == hs[j])
{
ls[i] = ls[j];
break;
}
else if (hs[i] > hs[j])
{
ls[i] = ls[j + 1];
break;
}
}
if (ls[i] == 0) ls[i] = 1;
break;
}
}
Console.Write(ls[0]);
for (int i = 1; i < ls.Length; i++)
{
Console.Write(",");
Console.Write(ls[i]);
}
Console.WriteLine();
int[] ns = new int[ls.Length];
ns[0] = 1;
Console.WriteLine(ns[0]);
for (int i = 1; i < ls.Length; i++)
{
for (int j = ls[i]; j < ls.Length; j++) //后面的填0
ns[j] = 0;
ns[ls[i] - 1]++;
Console.Write(ns[0]);
for (int j = 1; j < ls[i]; j++)
{
Console.Write(".");
Console.Write(ns[j]);
}
Console.WriteLine();
}