我想请教?
我想请教0,1,2等三个数字的排列,结果为:0
1
2
00
01
02
10
11
12
20
21
22
000
001
002
100
101
102
110
111
112
120
121
122
200
201
202
210
211
212
220
221
222
--------------------编程问答-------------------- 没头没尾的.不知所云. --------------------编程问答-------------------- 三个循环就好了 --------------------编程问答--------------------
--------------------编程问答-------------------- 扩展了一下楼主的功能,可以排列任意个数的字符,只要将其作为一个字符数组传参即可
static void Main(string[] args)
{
for (int a = 0; a < 3; a++)
for (int b = 0; b < 3; b++)
for (int c = 0; c < 3; c++)
Console.WriteLine(a * 100 + b * 10 + c);
}
--------------------编程问答-------------------- 顶了 --------------------编程问答-------------------- 以后需再关注,现在先帮你顶一下
static void Main(string[] args)
{
string[] s ={ "1", "2", "3","4","5" };
Matrix m = new Matrix(s);
Matrix[] m2 = m.Cal();
for (int i = 0; i < m2.Length; i++)
{
for (int j = 0; j < m2[i].element.Length; j++)
{
Console.WriteLine(m2[i].element[j]);
}
}
}
struct Matrix
{
public string[] element;
public Matrix(string[] s)
{
element = s;
}
public Matrix Multiply(Matrix m)
{
string[] s = new string[this.element.Length * m.element.Length];
int index = 0;
for (int i = 0; i < this.element.Length; i++)
{
for (int j = 0; j < m.element.Length; j++)
{
s[index] = this.element[i] + m.element[j];
index++;
}
}
return new Matrix(s);
}
public Matrix[] Cal()
{
Matrix[] m = new Matrix[this.element.Length];
m[0] = this;
for (int i = 1; i < m.Length; i++)
{
m[i] = this.Multiply(m[i - 1]);
}
return m;
}
}
补充:.NET技术 , 非技术区