首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

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

2012-09-03 
求M选N算法 非常急 求高手如题 C# 比如5选3最后输出123**12*4*12**51*34*1*3*51**45*234**23*5*2*45**345[

求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 等等

热点排行