小编Mar*_*ine的帖子

如何使用C ++ 20 std :: format?

C ++ 20引入std::format。与printf或相比有什么优势std::cout?我如何使用它,有人给它举例?

c++ printf cout string-formatting c++20

3
推荐指数
2
解决办法
123
查看次数

C#按绝对值对数组排序不适用于输入数组

使用输入数组按绝对值对数组进行排序不起作用,但是用简单的数组替换它是可行的。我不知道为什么它不起作用,我只是不知道出什么问题了。

我需要的结果是这样的:

输入: -5 4 8 -2 1

输出: 1 -2 4 -5 8

    static void Main()
    {
        var sampleInput =  Console.ReadLine().Split().Select(int.Parse).ToArray();

        int[] x = sampleInput;
        int n = sampleInput.Length;
            int[] output = new int[n];
            string sOutput = string.Empty;
            int start = 0;
            int last = n - 1;

            while (last >= start)
            {
                n--;
                if (Math.Abs(x[start]) > Math.Abs(x[last]))
                {
                    output[n] = x[start++];
                }
                else
                {
                    output[n] = x[last--];
                }

                sOutput = output[n].ToString() + " " + sOutput;
            }

            Console.Write(sOutput); …
Run Code Online (Sandbox Code Playgroud)

c# arrays sorting

-3
推荐指数
1
解决办法
90
查看次数

标签 统计

arrays ×1

c# ×1

c++ ×1

c++20 ×1

cout ×1

printf ×1

sorting ×1

string-formatting ×1