csharp进阶练习题:写号的扩展形式【难度:2级】:
写在扩展表格编号
你会得到一个号码,你需要将它作为字符串返回[扩展形式(https://www.mathplacementreview.com/arithmetic/whole-numbers.php#expanded-form).例如:
expandedForm 12 - 应该返回'10 + 2'
expandedForm 42 - 应该返回'40 + 2'
expandedForm 70304 - 应该返回 '70000 + 300 + 4'
expandedForm(12); //应该返回'10 + 2'
expandedForm(42); //应该返回'40 + 2'
expandedForm(70304); //应该返回 '70000 + 300 + 4'
expanded_form(12)# 应返回'10 + 2'
expanded_form(42)# 应返回'40 + 2'
expanded_form(70304)# 如果返回 '70000 + 300 + 4'
expanded_form(12); //应该返回 "10 + 2"
expanded_form(42); //应该返回 "40 + 2"
expanded_form(70304); //应该返回 "70000 + 300 + 4"
expanded_form(12);# 应该返回'10 + 2'
expanded_form(42);# 应该返回'40 + 2'
expanded_form(70304);# 应该返回 '70000 + 300 + 4'
expandedForm(12);# 应该返回'10 + 2'
expandedForm(42);# 应该返回'40 + 2'
expandedForm(70304);# 应该返回 '70000 + 300 + 4'
Kata.expandedForm(12);# 应返回 "10 + 2"
Kata.expandedForm(42);# 应返回 "40 + 2"
Kata.expandedForm(70304);# 应返回 "70000 + 300 + 4"
Kata.ExpandedForm(12);# 应返回 "10 + 2"
Kata.ExpandedForm(42);# 应返回 "40 + 2"
Kata.ExpandedForm(70304);# 应返回 "70000 + 300 + 4"
expandedForm 12L //应该返回 "10 + 2"
expandedForm 42L //应该返回 "40 + 2"
expandedForm 70304L //应该返回 "70000 + 300 + 4"
注:所有数字将完整的数字大于0.
如果你喜欢这个习题,检查出[第2部分(https://www.codewars.com/kata/write-number-in-expanded-form-part-2)!
编程目标:
using System;
public static class Kata
{
public static string ExpandedForm(long num)
{
throw new NotImplementedException();
}
}
测试样例:
namespace Solution
{
using NUnit.Framework;
using System;
[TestFixture]
public class SolutionTest
{
[Test]
{
Assert.That(Kata.ExpandedForm(12), Is.EqualTo("10 + 2"));
Assert.That(Kata.ExpandedForm(42), Is.EqualTo("40 + 2"));
Assert.That(Kata.ExpandedForm(70304), Is.EqualTo("70000 + 300 + 4"));
}
}
}
最佳答案(多种解法):
更多关联题目:
csharp高级练习题:路线减少【难度:3级】–景越C# 经典编程题库,不同难度C# 练习题,适合自学C# 的新手进阶训练
免责申明
本博客所有编程题目及答案均收集自互联网,主要用于供网友学习参考,如有侵犯你的权益请联系管理员及时删除,谢谢
题目收集至https://www.codewars.com/
https://www.codewars.com/kata/write-number-in-expanded-form