csharp基础练习题:算上猴子!【难度:0级】:
你把你的儿子去森林看猴子.你知道,有一定数量的有(n)的,但你的儿子太年轻,只欣赏完整号码,他已经开始从1计数它们.
作为一个好家长,你会坐下来和他一起算.鉴于数(n),填充的所有数值的数组至多且包括该号码,但不包括零.
例如:
monkeyCount(10)// - > [1,2,3,4,5,6,7,8,9,10]
monkeyCount(1)// - > [1]
去
monkeyCount(10)// - > [] INT {1,2,3,4,5,6,7,8,9,10}
monkeyCount(1)// - > [] INT {1}
monkeyCount(10)// - > [1,2,3,4,5,6,7,8,9,10]
monkeyCount(1)// - > [1]
monkeyCount(10)# - > [1,2,3,4,5,6,7,8,9,10]
monkeyCount(1)# - > [1]
monkeyCount(10)# - > [1,2,3,4,5,6,7,8,9,10]
monkeyCount(1)# - > [1]
monkeyCount(10)// - >新INT [] {1,2,3,4,5,6,7,8,9,10}
monkeyCount(1)// - >新INT [] {1}
monkeyCount(10)// - >新INT [] {1,2,3,4,5,6,7,8,9,10}
monkeyCount(1)// - >新INT [] {1}
编程目标:
public static class MonkeyCounter
{
public static int[] MonkeyCount(int n)
{
throw new System.NotImplementedException();
}
}
测试样例:
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using System;
[TestFixture]
public class Tests
{
public static object[] FixedTests =
new object[] { MonkeyCounter.MonkeyCount(5), new int[]{1,2,3,4,5} },
new object[] { MonkeyCounter.MonkeyCount(3), new int[]{1,2,3} },
new object[] { MonkeyCounter.MonkeyCount(9), new int[]{1,2,3,4,5,6,7,8,9} },
new object[] { MonkeyCounter.MonkeyCount(10), new int[]{1,2,3,4,5,6,7,8,9,10} },
new object[] { MonkeyCounter.MonkeyCount(20), new int[]{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20} }
};
[Test, TestCaseSource("FixedTests")]
最佳答案(多种解法):
更多关联题目:
免责申明
本博客所有编程题目及答案均收集自互联网,主要用于供网友学习参考,如有侵犯你的权益请联系管理员及时删除,谢谢
题目收集至https://www.codewars.com/
https://www.codewars.com/kata/count-the-monkeys