csharp基础练习题:排序值和索引数组【难度:1级】:
显示结果值和索引数组
你的任务是价值的产品和位置的索引排序整数数组.
搜索结果
对于分类指数从1开始,而不是在0!点击
排序,必须上升.结果
该数组矩阵将永远不会为空,将始终包含数字.
搜索结果
例:
输入:23,2,3,4,5
价值和指数产品:
23 => 23×1 = 23 - >输出-Pos的4
2 => 2 * 2 = 4 - >输出-Pos的1
3 => 3 * 3 = 9 - >输出-Pos的2
4 => 4 * 4 = 16 - >输出-Pos的3
5 => 5 * 5 = 25 - >输出-Pos的5
输出:2,3,4,23日,5
点击搜索结果
有乐趣的编码它,请不要忘记投票和排列此习题! ?
我也创建其他练习题.看看,如果你喜欢这篇习题!
编程目标:
using System;
public class Kata
{
public static int[] SortByValueAndIndex(int[] array)
{
return array;
}
}
测试样例:
namespace Solution
{
using NUnit.Framework;
using System;
public class KataTests
{
[Test]
public void ExampleTests()
var actual = Kata.SortByValueAndIndex(new int[] { 1, 2, 3, 4, 5 });
var expected = new int[] { 1, 2, 3, 4, 5 };
var message = "Your result:\n" + ArrayToString(actual) + "\n\nExpected result:\n" + ArrayToString(expected);
Assert.AreEqual(expected, actual, message);
actual = Kata.SortByValueAndIndex(new int[] { 23, 2, 3, 4, 5 });
expected = new int[] { 2, 3, 4, 23, 5 };
message = "Your result:\n" + ArrayToString(actual) + "\n\nExpected result:\n" + ArrayToString(expected);
最佳答案(多种解法):
更多关联题目:
免责申明
本博客所有编程题目及答案均收集自互联网,主要用于供网友学习参考,如有侵犯你的权益请联系管理员及时删除,谢谢
题目收集至https://www.codewars.com/
https://www.codewars.com/kata/sort-an-array-by-value-and-index