版权声明:本人菜鸟一只,如文章有错误或您有高见,请不吝赐教 https://blog.csdn.net/qq_41138935/article/details/83348128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp11列表排序
{
class Student : IComparable<Student>
{
public string StuNum;
public string Name;
public float Chinese;
public float English;
public float Math;
public float Tot;
public Student(string[] s)
{
StuNum = s[0];
Name = s[1];
Chinese = float.Parse(s[2]);
English = float.Parse(s[3]);
Math = float.Parse(s[4]);
Tot = Chinese + English + Math;
}
public int CompareTo(Student other)
{
return (int)(other.Tot - this.Tot);
}
public override string ToString()
{
return StuNum + "\t" + Name + "\t" + Chinese + "\t" + English + "\t" + Math + "\t" + Tot;
}
}
class Program
{
static void Main(string[] args)
{
string[] s = new string[5];
string str="";
List<Student> L1 = new List<Student>();
while ((str = Console.ReadLine()) != "")
{
s = str.Split('\t');
L1.Add(new Student(s));
}
L1.Sort();
Console.WriteLine("------------------------总分排名------------------------");
Console.WriteLine("学号\t姓名\t语文\t英语\t数学\t总分");
foreach (Student stu in L1)
{
Console.WriteLine(stu);
}
Console.ReadLine();
}
}
}