asp.Netは3ビットの異なる数字の組み合わせの数を求めます
3762 ワード
簡単:
CSDNの(xiaoshen 1127):WINFORM版
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 {
m1 = ssel + ssel.Substring(i, 1);
Response.Write(m1.Remove(i,1) + "
");
}
}
}
CSDNの(xiaoshen 1127):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 als = new List();
als = p.GetData(string.Empty, num.Trim(), als);
p.Display(als);
Console.WriteLine("
Y-Enter: ");
if (Console.ReadLine().Trim().ToLower() == "y")
{
Console.Clear();
Main(args);
}
}
catch {
Console.Clear();
Console.WriteLine(" !");
Main(args);
}
}
private List GetData(String strBase, String strSel, List 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 {
GetData(strBase + strSel.Substring(i, 1), strSel.Remove(i, 1), alRet);
}
}
return alRet;
}
public void Display(List 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();
}
}
}
}
}
}