读书人

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

发布时间: 2012-09-03 09:48:39 作者: rapoo

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

读书人网 >asp.net

热点推荐