简单的:
复制代码 代码如下:
public partial class _Default : System.Web.UI.Page
{
string m1 = "";
protected void Page_Load(object sender, EventArgs e)
{
string n = "123";
string m = "";
zuhe(n);
for (int j = 2; j > -1; j--)
{
m = m + n[j];
}
zuhe(m);
}
private void zuhe(string ssel)
{
for (int i = 0; i < ssel.Length; i++)
{
m1 = ssel + ssel.Substring(i, 1);
Response.Write(m1.Remove(i,1) + "<br>");
}
}
}
CSDN的(xiaoshen1127 ):WINFORM版
复制代码 代码如下:
using System;
using System.Collections.Generic;
namespace ZuHeShu
{
class Program
{
static void Main(string[] args)
{
Program p = new Program();
Console.WriteLine("******************************组合数***********************************");
Console.WriteLine("请任意输入一个整数:");
string num = Console.ReadLine();
try {
long.Parse(num);
List<string> als = new List<string>();
als = p.GetData(string.Empty, num.Trim(), als);
p.Display(als);
Console.WriteLine("\nY-Enter:继续");
if (Console.ReadLine().Trim().ToLower() == "y")
{
Console.Clear();
Main(args);
}
}
catch {
Console.Clear();
Console.WriteLine("请输入数字!");
Main(args);
}
}
private List<string> GetData(String strBase, String strSel, List<string> alRet)
{
if (strSel.Length == 1)
{
string temp=strBase + strSel;
if (!alRet.Contains(temp)&&!temp.StartsWith("0"))
{
alRet.Add(temp);
}
}
else
{
for (int i = 0; i < strSel.Length; i++)
{
GetData(strBase + strSel.Substring(i, 1), strSel.Remove(i, 1), alRet);
}
}
return alRet;
}
public void Display(List<string> dals)
{
int i = 1;
int a = dals.Count;
if (a == 0)
{
Console.WriteLine("该数没有其他组合情况");
}
else
{
Console.WriteLine("不同的组合数共有" + a + "个,如下");
foreach (string number in dals)
{
Console.Write(number + "\t");
if (i++ % 5 == 0)
{
Console.WriteLine();
}
}
}
}
}
}
复制代码 代码如下:
public partial class _Default : System.Web.UI.Page
{
string m1 = "";
protected void Page_Load(object sender, EventArgs e)
{
string n = "123";
string m = "";
zuhe(n);
for (int j = 2; j > -1; j--)
{
m = m + n[j];
}
zuhe(m);
}
private void zuhe(string ssel)
{
for (int i = 0; i < ssel.Length; i++)
{
m1 = ssel + ssel.Substring(i, 1);
Response.Write(m1.Remove(i,1) + "<br>");
}
}
}
CSDN的(xiaoshen1127 ):WINFORM版
复制代码 代码如下:
using System;
using System.Collections.Generic;
namespace ZuHeShu
{
class Program
{
static void Main(string[] args)
{
Program p = new Program();
Console.WriteLine("******************************组合数***********************************");
Console.WriteLine("请任意输入一个整数:");
string num = Console.ReadLine();
try {
long.Parse(num);
List<string> als = new List<string>();
als = p.GetData(string.Empty, num.Trim(), als);
p.Display(als);
Console.WriteLine("\nY-Enter:继续");
if (Console.ReadLine().Trim().ToLower() == "y")
{
Console.Clear();
Main(args);
}
}
catch {
Console.Clear();
Console.WriteLine("请输入数字!");
Main(args);
}
}
private List<string> GetData(String strBase, String strSel, List<string> alRet)
{
if (strSel.Length == 1)
{
string temp=strBase + strSel;
if (!alRet.Contains(temp)&&!temp.StartsWith("0"))
{
alRet.Add(temp);
}
}
else
{
for (int i = 0; i < strSel.Length; i++)
{
GetData(strBase + strSel.Substring(i, 1), strSel.Remove(i, 1), alRet);
}
}
return alRet;
}
public void Display(List<string> dals)
{
int i = 1;
int a = dals.Count;
if (a == 0)
{
Console.WriteLine("该数没有其他组合情况");
}
else
{
Console.WriteLine("不同的组合数共有" + a + "个,如下");
foreach (string number in dals)
{
Console.Write(number + "\t");
if (i++ % 5 == 0)
{
Console.WriteLine();
}
}
}
}
}
}
标签:
asp.net,不同数字,组合数
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
狼山资源网 Copyright www.pvsay.com
暂无“asp.net求3位不同数字的组合数”评论...