111,094
社区成员




using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string[] charString = { "L", "O", "V", "E" };
for (int i = 0; i < Total.Count; i++)
{
Console.WriteLine(Total[i]);
}
Console.ReadKey();
}
List<string> Total = new List<string>();
/// <summary>
/// 全排列
/// </summary>
/// <param name="charString">排列源字符</param>
/// <param name="count">排列数目</param>
/// <param name="str"></param>
public void test(string[] charString, int count, string str="")
{
foreach (string wd in charString)
{
string newStr = str + wd;
if (newStr.Length > count-1)
{
Total.Add(newStr);
}
else
{
test(charString, count, newStr);
}
}
}
}
}
.
.
抄袭加改造。这个算不算
.
.using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var result = Arrange(4);
foreach (var item in result)
{
Console.WriteLine(string.Join(",", item.Select(x => x.ToString()).ToArray()));
}
}
static IEnumerable<IEnumerable<int>> Arrange(int n, IEnumerable<IEnumerable<int>> seed = null)
{
if (seed == null)
seed = Enumerable.Range(0, n).Select(x => new List<int>() { x });
if (seed.First().Count() == n)
{
foreach (var item in seed)
yield return item;
}
else
{
foreach (var item in Arrange(n, seed.SelectMany(x => Enumerable.Range(0, n).Except(x).Select(y => x.Concat(new List<int>() { y })))))
yield return item;
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var result = Arrange(4);
foreach (var item in result)
{
Console.WriteLine(string.Join(",", item.Select(x => x.ToString()).ToArray()));
}
}
static IEnumerable<IEnumerable<int>> Arrange(int n, IEnumerable<IEnumerable<int>> seed = null)
{
if (seed == null)
seed = Enumerable.Range(0, n).Select(x => new List<int>() { x });
if (seed.First().Count() == n) return seed;
return Arrange(n, seed.SelectMany(x => Enumerable.Range(0, n).Except(x).Select(y => x.Concat(new List<int>() { y }))));
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var result = Arrange(4);
foreach (var item in result)
{
Console.WriteLine(string.Join(",", item.Select(x => x.ToString()).ToArray()));
}
}
static IEnumerable<IEnumerable<int>> Arrange(int n)
{
IEnumerable<IEnumerable<int>> result = Enumerable.Range(0, n).Select(x => new List<int>() { x });
while (result.First().Count() < n)
{
result = result.SelectMany(x => Enumerable.Range(0, n).Except(x).Select(y => x.Concat(new List<int>() { y })));
}
return result;
}
}
}