62,051
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string s = "12345";
List<string> list = new List<string>();
foreach (var i in Combo(s, 4))
{
list = list.Union(Arrange(i)).ToList();
}
Console.WriteLine(list.Count);
//list.ForEach(x => Console.WriteLine(x));
}
static IEnumerable<string> Arrange(string source)
{
for (int i = 0; i < source.Length; i++)
{
if (source.Length == 1)
{
yield return source;
}
else
{
foreach (var x in Arrange(source.Substring(0, i) + source.Substring(i + 1)))
{
yield return source[i] + x;
}
}
}
}
static IEnumerable<string> Combo(string source, int len)
{
int[] pos = new int[len];
for (int i = 0; i < len; i++) pos[i] = i;
while (pos[0] < source.Length - len)
{
string str = "";
for (int i = 0; i < len; i++) str += source[pos[i]];
for (int i = len - 1; i >= 0; i--)
{
if (pos[i] < source.Length - len + i)
{
pos[i]++;
for (int j = i + 1; j <= len - 1; j++)
{
pos[j] = pos[i] + j - i;
}
break;
}
else
{
continue;
}
}
yield return str;
}
yield return source.Substring(source.Length - len);
}
}
}
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Galsun.Nfdw.Web
{
public partial class index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
int[] ary = new int[] { 0, 1, 2, 2 };
ary.CopyTo(ary, 0);
int s = 3;
string num = "1233";
char[] ary_num = num.ToCharArray();
int n = ary_num.Length - 1;
int cout = 0;
string txt = string.Empty;
while (s >= 0)
{
loop: if (ary[s] >= n)
{
ary[s] = -1;
s = s - 1;
}
else
{
ary[s] = ary[s] + 1;
for (int i = s - 1; i >= 0; i--)
{
if (ary[s] == ary[i])
{
goto loop;
}
}
if (s == 3 && !txt.Contains(string.Format("{0}{1}{2}{3}", ary_num[ary[0]], ary_num[ary[1]], ary_num[ary[2]], ary_num[ary[3]])))
{
cout++;
txt = txt + "," + string.Format("{0}{1}{2}{3}", ary_num[ary[0]], ary_num[ary[1]], ary_num[ary[2]], ary_num[ary[3]]);
Response.Write(string.Format("{0}{1}{2}{3}<br/>", ary_num[ary[0]], ary_num[ary[1]], ary_num[ary[2]], ary_num[ary[3]]));
}
if (s < 3)
{
s = s + 1;
}
}
}
Response.Write(string.Format("{1}总数为:{0} 个数列", cout, num));
}
}
}
}
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Galsun.Nfdw.Web
{
public partial class index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
int[] ary = new int[] { 0, 1, 2, 2 };
ary.CopyTo(ary, 0);
int s = 3;
string num = "12345";
char[] ary_num = num.ToCharArray();
int n = ary_num.Length - 1;
int cout = 0;
while (s >= 0)
{
loop: if (ary[s] >= n)
{
ary[s] = -1;
s = s - 1;
}
else
{
ary[s] = ary[s] + 1;
for (int i = s - 1; i >= 0; i--)
{
if (ary[s] == ary[i])
{
goto loop;
}
}
if (s == 3)
{
cout++;
Response.Write(string.Format("{0}{1}{2}{3}<br/>", ary_num[ary[0]], ary_num[ary[1]], ary_num[ary[2]], ary_num[ary[3]]));
}
if (s < 3)
{
s = s + 1;
}
}
}
Response.Write(string.Format("总数为:{0} 个数列", cout));
}
}
}
}
int[] sourceIntegerArray = new int[4] { 1, 2, 3, 4};
int[] oneOfIntegerResults = new int[4];
List<int[]> resultIntegerList = new List<int[]>();
protected void Page_Load(object sender, EventArgs e)
{
ArrangeInteger(oneOfIntegerResults.Length, sourceIntegerArray.Length, 0);
Response.Write(resultIntegerList.Count + "项结果<br/>");
for (int i = 0; i < resultIntegerList.Count; i++)
{
for (int j = 0; j < resultIntegerList[i].Length; j++)
Response.Write(resultIntegerList[i][j]);
Response.Write("<br/>");
}
}
private void ArrangeInteger(int takeCount, int totalCount, int depth)
{
if (takeCount > 0)
{
for (int i = 0; i < sourceIntegerArray.Length; i++)
{
bool IsExist = false;
for (int j = 0; j < oneOfIntegerResults.Length; j++)
{
if (sourceIntegerArray[i] == oneOfIntegerResults[j])
{
IsExist = true;
break;
}
}
if (!IsExist)
{
oneOfIntegerResults[depth] = sourceIntegerArray[i];
ArrangeInteger(takeCount - 1, totalCount - 1, depth + 1);
}
for (int j = depth; j < oneOfIntegerResults.Length; j++)
oneOfIntegerResults[j] = int.MinValue;
}
}
else
{
int[] temp = new int[oneOfIntegerResults.Length];
for (int i = 0; i < temp.Length; i++)
temp[i] = oneOfIntegerResults[i];
resultIntegerList.Add(temp);
}
}
}