110,534
社区成员
发帖
与我相关
我的任务
分享
function count() {
result = "";
for (i1 = 0; i1 <= 10; i1++) {
for (i2 = 0; i2 <= 10 - i1; i2++) {
for (i3 = 0; i3 <= 10 - i1 - i2; i3++) {
for (i4 = 0; i4 <= 10 - i1 - i2 - i3; i4++) {
for (i5 = 0; i5 <= 10 - i1 - i2 - i3 - i4; i5++) {
for (i6 = 0; i6 <= 10 - i1 - i2 - i3 - i4 - i5; i6++) {
for (i7 = 0; i7 <= 10 - i1 - i2 - i3 - i4 - i5 - i6; i7++) {
for (i8 = 0; i8 <= 10 - i1 - i2 - i3 - i4 - i5 - i6 - i7; i8++) {
for (i9 = 0; i9 <= 10 - i1 - i2 - i3 - i4 - i5 - i6 - i7 - i8; i9++) {
i10 = 10 - i1 - i2 - i3 - i4 - i5 - i6 - i7 - i8 - i9
result += i1 + " " + i2 + " " + i3 + " " + i4 + " " + i5 + " " + i6 + " " + i7 + " " + i8 + " " + i9 + " " + i10 + " "
}
}
}
}
}
}
}
}
}
$("#abc").html(result);
}
public static class Class1<T>
{
private static int m = 0;
private static List<T> tempList = new List<T>();
public static void GetResult(List<T> list, int num, int startIndex, ref List<List<T>> outputList)
{
m++;
for (int i = startIndex; i < list.Count; i++)
{
tempList.Add(list[i]);
if (m == num)
{
T[] array = new T[num];
tempList.CopyTo(array);
outputList.Add(array.ToList());
}
else
{
GetResult(list, num, i + 1, ref outputList);
}
tempList.Remove(list[i]);
}
m--;
}
}
textBox1.Clear();
int i = 1;
for (int i1 = 1; i1 <= 2; i1++)
for (int i2 = i1; i2 <= 2; i2++)
for (int i3 = i2; i3 <= 2; i3++)
{
textBox1.Text += i.ToString() + " " + i1.ToString() + " " + i2.ToString() + " " + i3.ToString() + "\r\n";
i++;
}
var index = 1;
for (var index01 = 1; index01 <= 2; index01++)
{
var index01X = index01;
for (var index02 = 1; index02 <= 2; index02++)
{
var index02X = index02;
for (var index03 = 1; index03 <= 2; index03++)
{
var index03X = index03;
Console.WriteLine(index + @"." + index01X + @"-" + index02X + @"-" + index03X);
}
}
index++;
}
// 结果是:
1. 1 1 1
2. 1 1 2
3. 1 2 1 // 与2重复(顺序不同,也算重复),舍弃
4. 1 2 2
5. 2 1 1 // 与2重复(顺序不同,也算重复),舍弃
6. 2 1 2 // 与4重复(顺序不同,也算重复),舍弃
7. 2 2 1 // 与4重复(顺序不同,也算重复),舍弃
8. 2 2 2