ASP.NET教程:多个Set排列算法
using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;
public class Test{
public static void Main(string [] args){
string CheckDefault="A,B,C;D,E;G,F,J";
string[] Lists=CheckDefault.Split(';');
int MAXResult=1;
int MAXColum=Lists.Length;
List<string[]> c=new List<string[]>(MAXColum);
for(int i=0;i< MAXColum;i++){
c.Add(Lists[i].Split(','));
MAXResult*=c[i].Length;
}
int[] k=new int[MAXColum];
for(int i=0;i<MAXResult;i++){
for(int j=0;j<MAXColum;j++){
Console.Write( c[j][k[j]]+(j==MAXColum-1?"\r\n":""));
}
AddOne(c,ref k);
}
Console.WriteLine("总数是{0}",MAXResult);
}
public static void AddOne(List<string[]> c,ref int[] k){
int zoomCol=k.Length-1;
while(zoomCol>0 && k[zoomCol]+1 == c[zoomCol].Length){
k[zoomCol]=0;
zoomCol--;
}
k[zoomCol]+=1;
}
}