求助:这个程序编的对吗?能否继续简化???
读取全站仪数据(Longquanshan.txt),将x, y, h 读取到数组中,以x从小到大排序,将排序的结果输出到文本文件中。using System;
using System.Collections.Generic;
using System.Text;
using
namespace 龙泉山
{
class Program
{
static void Main(string[] args)
{
string path = @"D:\longquanshan.txt";
string[] readText = File.ReadAllLines(path);
string []s=new string [3];
float [] x = new float [readText.Length];
float [] y = new float [readText.Length];
float [] h = new float [readText.Length];
for (int i = 0; i <readText.Length; i++)
{
t = readText[i].Split('\t');
x[i] = float.Parse(t[0]);
y[i] = float.Parse(t[1]);
h[i] = float.Parse(t[2]);
}
bool sign = true;
for (int i = 0; i <readText.Length&&sign ; i++)
{
sign = false;
for (int j = i+1; j < readText.Length; j++)
{
if (x[i] > x[j])
{
sign = true;
float temp = x[i];
x[i] = x[j];
x[j] = temp;
temp = y[i];
y[i] = y[j];
y[j] = temp;
h[i] = h[j];
h[j] = temp;
}
}
}
string path1 = @"D:\Newlongquanshan.txt";
if (!File.Exists(path1))
{
using (StreamWriter sw = File.CreateText(path1))
for (int i =0; i <readText.Length; i++)
{
sw.WriteLine(x[i] + "\t" + y[i] + "\t" + h[i]);
}
}
using (StreamReader sr = File.OpenText(path1))
{
string str = "";
while ((str = sr.ReadLine()) != null)
{
Console.WriteLine(str);
}
}
Console.ReadLine();
}
}
}