文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>组合数 c#

组合数 c#

时间:2010-09-27  来源:lovebanyi

假设我们有两个或多个数组。
{"a","b"}
{"c","d"}
跟据我们学过的组合知识我们知道它可以组合成 ac ad bc bd 然后如果有很多数组的时候我们要什么来编程。
{"a" ,"b", "c"}
{"1" ,"2" ,"3"}
{"!","@","#"}

(一开始我的思想绕了一个弯,我没有直接想出来要什么弄,我在想多个是要不断的递归下去,但是一直没有想到要什么去递归)
于是我就开始回到最简单的时候两个的时候什么办。发现两个的时候蛮简单的,两个循环合并起来就行了,然后灵光一闪其它的不也是这样吗。
他两个合起来的结果当作一个就行了。


主要会用在电子商务系统里的 产品的属性值

void Main()
{
    List<List<string>> s = new List<List<string>>();
    s.Add(new List<string>(){"a","b","c"});
    s.Add(new List<string>(){"1","2","3"});
    s.Add(new List<string>(){"!","@","#"});
    s.Add(new List<string>(){"[","]","{","}"});
    
    var result =Combin(s);
    result.Dump();
}

List<string> Combin(List<List<string>> s)
{
    var temp = s[0];
    for(int i=1;i<s.Count;i++)
    {
        temp = Multiplication(temp,s[i]);
    }
    return temp;
}

List<string> Multiplication(List<string> a,List<string> b)
{
    List<string> result = new List<string>();
    for(int i=0;i<a.Count;i++)
    {
        for(int j=0;j<b.Count;j++)
        {
            result.Add(a[i]+","+b[j]);
        }
    }
    return result;
}
// Define other methods and classes here
结果

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载