当前位置: 代码迷 >> ASP.NET >> 求M选N算法 十分急 求高手
  详细解决方案

求M选N算法 十分急 求高手

热度:6557   发布时间:2013-02-25 00:00:00.0
求M选N算法 非常急 求高手
如题 C# 比如5选3 

最后输出  
123**
12*4*
12**5
1*34*
1*3*5
1**45
*234*
*23*5
*2*45
**345

------解决方案--------------------------------------------------------
C# code
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{    class Program    {        static void Main(string[] args)        {            string s = "12345";            var query = from x in s                        from y in s                        where x != y                        select s.Replace(x, '*').Replace(y, '*');            foreach (var item in query)                Console.WriteLine(item);        }    }}
------解决方案--------------------------------------------------------
C# code
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{    class Program    {        static void Main(string[] args)        {            string s = "12345";            var query = (from x in s                        from y in s                        where x != y                        orderby x + y descending                        select s.Replace(x, '*').Replace(y, '*')).Distinct();            foreach (var item in query)                Console.WriteLine(item);        }    }}
------解决方案--------------------------------------------------------
探讨
这个能通用吗 可能有8选5 7选3 等等
  相关解决方案