111,092
社区成员




FUN(最小长度,最大长度)
{
if(最小长度是0)
{
就只生成最大长度
}
else
{
从最小长度开生成起,一直大最大长度
}
}
class Program
{
public static String[] A={"a","b","c","d","1","2","3"};
static void Main(string[] args)
{
min_miax(1,2);//改这儿就OK
}
public static void min_miax(int min, int max)
{
if (min == 0)
{
find(max, "");
}
else
{
for (int i = min; i <= max; i++)
{ find(i, ""); }
}
}
public static void find(int flag, String str)
{
if(flag==str.Length)
{
Console.WriteLine(str);
}
else
{
for(int i=0;i<=A.Length-1;i++ )
{
find(flag,str+A[i]);
}
}
}
}
class Program
{
public static String[] A={"a","b","c","d","1","2","3"};
static void Main(string[] args)
{
min_miax(1,2);//改这儿就OK
}
public static void min_miax(int min, int max)
{
if (min == 0)
{
find(max, "");
}
else
{
for (int i = min; i <= max; i++)
{ find(i, ""); }
}
}
public static String find(int flag, String str)
{
if(flag==str.Length)
{
Console.WriteLine(str);
return str;
}
else
{
for(int i=0;i<=A.Length-1;i++ )
{
find(flag,str+A[i]);
}
}
return "";
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication9
{
class Program
{
void Permutation(char[] pStr, int begin, int end)
{
if (begin == end - 1) //只剩一个元素
{
for (int i = 0; i < end; i++) //打印
Console.Write(pStr[i]);
Console.WriteLine(string.Empty);
}
else
{
for (int k = begin; k < end; k++)
{
swap(ref pStr[k], ref pStr[begin]); //交换两个字符
Permutation_Solution1(pStr, begin + 1, end);
swap(ref pStr[k], ref pStr[begin]); //恢复
}
}
}
private void swap(ref char p1,ref char p2)
{
char c;
c = p1;
p1 = p2;
p2 = c;
}
static void Main(string[] args)
{
char[] c = { 'a', 'b', 'c', 'd' };
Program g = new Program();
for (int j = 0; j < 4; j++)
{
g.Permutation(c, 0, j+1);
}
Console.ReadKey();
}
}
}
这种只能求出不带重复的