读书人

求C#大神速速来解~该如何解决

发布时间: 2013-08-06 16:47:25 作者: rapoo

求C#大神速速来解~~~~~~~~~~~~
本人C#菜鸟一只,如有不到之处还请谅解!
问题如下:


Q1:一个楼道有n(>=3)个阶梯 有几种方法上去 例如 3 1 1 1 21 12


Q2:n(>=6)个数去掉其中的一个 成为最小 例如 133427 去掉4 是最小的


PS:简单明了的解答,谢谢您勒!

C# 算法 问题 大神
[解决办法]
for (int i=1;i>=n.length;i++){
int[i]=(int)(n.tostring().remove(i,?1));}
int[].min();
手机打字不行第二个我想是这样的
[解决办法]

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("problem1(3):");
foreach (var item in problem1(3))
{
Console.WriteLine(string.Join(",", item.Select(x => x.ToString()).ToArray()));
}
Console.WriteLine("problem1(4):");
foreach (var item in problem1(4))
{
Console.WriteLine(string.Join(",", item.Select(x => x.ToString()).ToArray()));
}
Console.WriteLine("problem2(133427):");
Console.WriteLine(problem2(133427));


}

static IEnumerable<IEnumerable<int>> problem1(int n)
{
return Enumerable.Range(1, n - 1)
.SelectMany(x => problem1(n - x).Select(y => new int[] { x }.Concat(y))).Concat(new int[][] { new int[] { n }});
}

static int problem2(int n)
{
int[] data = n.ToString().Select(x => x - '0').ToArray();
var query = Enumerable.Range(0, data.Length)
.Select(x => new
{
k = data[x],
v = data.Select((y, i) => new { y, i }).Where(y => y.i != x).ToList().Select((y, i) => (int)Math.Pow(10.0, (double)(data.Length - 2 - i)) * y.y).Sum()
});
return query.OrderBy(x => x.v).First().k;
}
}
}



problem1(3):
1,1,1
1,2
2,1
3
problem1(4):
1,1,1,1
1,1,2
1,2,1
1,3
2,1,1
2,2
3,1
4
problem2(133427):
4
Press any key to continue . . .

读书人网 >C#

热点推荐