我有以下编译为Sort.exe的C#代码:
using System;
using System.Collections.Generic;
class Test
{
public static int Main(string[] args)
{
string text = null;
List<string> lines = new List<string>();
while((text = Console.In.ReadLine()) != null)
{
lines.Add(text);
}
lines.Sort();
foreach(var line in lines)
Console.WriteLine(line);
return 0;
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个文件input.txt,其中包含以下5行:
x000000000000000000093.000000000
x000000000000000000037.000000000
x000000000000000100000.000000000
x000000000000000000538.000000000
x-00000000000000000020.000000000
Run Code Online (Sandbox Code Playgroud)
现在,如果我在命令提示符下运行它,则输出如下:
C:\Users\girijesh\AppData\Local\Temp>sort < input.txt
x000000000000000000037.000000000
x000000000000000000093.000000000
x-00000000000000000020.000000000
x000000000000000000538.000000000
x000000000000000100000.000000000
Run Code Online (Sandbox Code Playgroud)
我无法理解字符串排序是什么样的字符串开头的字符串x-(输出中的第3行)出现在字符串的中间x0.第三行应该位于顶部或底部.Excel也显示相同的行为.