[c#]代码库
using System;
namespace demo4
{
class descompose
{
static uint[] iArray = new uint[100];
public static void Main(String[] args)
{
uint n = 0;
//bool inp = true;
Console.WriteLine("Please input a number whose type is unit:");
/*while(inp == true)
{
if(uint.TryParse(Console.ReadLine(),out n) == false)
{
Console.WriteLine("输入不合法!");
inp = true;
}
else
{
iArray[0] = n;
inp = false;
break;
}
}*/
while (!uint.TryParse(Console.ReadLine(),out n))
Console.WriteLine("格式不正确,重新输入:\n");
iArray[0] = n;
uint k = 1;
decompose(n,k);
}
private static void decompose(uint n,uint k)
{
uint i = (n < iArray[k - 1]) ? n : iArray[k - 1];
while (i > 0)
{
iArray[k] = i;
if(i == n)
{
Console.Write("\r\n{0} = {1}",iArray[0],iArray[1]);
for(uint j = 2; j <= k; j++)
{
Console.Write("+ {0}",iArray[j]);
}
}
else
{
decompose(n - i,k + 1);
}
i--;
}
}
}
}
by: 发表于:2018-01-12 14:34:11 顶(0) | 踩(0) 回复
??
回复评论