csharp基础练习题:完成该模式#2【难度:1级】:
<字型= “影响” 大小= “10”>
的 <字型= “影响” 大小= “10”> NEXT KATA> </跨度>
任务:
你必须写一个函数pattern
返回下面的模式(见模式与范例)高达行N
数.
- 注:
Returning
的模式是不一样Printing
格局.
规则/注意事项:
- 如果
ñ<1
那么它应该返回"",即空字符串. - 有
在模式没有whitespaces
.
模式:
(N)(N-1)(N-2)… 4321
(N)(N-1)(N-2)… 432
(N)(N-1)(N-2)… 43
(N)(N-1)(N-2)… 4
…
…
(N)(N-1)(N-2)
(N)(N-1)
(n)的
例子:
- 图案(4):
4321
432
43
4
- 图案(11):
1110987654321
111098765432
11109876543
1110987654
111098765
11109876
1110987
111098
11109
1110
11
提示:使用\ n的字符串跳转到下一行
LIST ALL MY作者KATAS <<<
编程目标:
using System;
public class Kata
{
public string Pattern(int n)
{
return "";
}
}
测试样例:
using System;
using NUnit.Framework;
[TestFixture]
public class Tests {
Kata k = new Kata();
[Test]
public void SimpleNumbers(){
Assert.AreEqual("1", k.Pattern(1));
Assert.AreEqual("54321\n5432\n543\n54\n5", k.Pattern(5));
}
}
最佳答案(多种解法):
更多关联题目:
免责申明
本博客所有编程题目及答案均收集自互联网,主要用于供网友学习参考,如有侵犯你的权益请联系管理员及时删除,谢谢
题目收集至https://www.codewars.com/
https://www.codewars.com/kata/complete-the-pattern-number-2