15-07-10 结构体-输入学生成绩进行排序
生活随笔
收集整理的這篇文章主要介紹了
15-07-10 结构体-输入学生成绩进行排序
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
輸入每個學生的學習成績,根據總分進行排序
? ? ? ? ? struct Student? ? ? ? ? {
? ? ? ? ? public string name;
? ? ? ? ? public int age;
? ? ? ? ? public double Cshap;
? ? ? ? ? public double Database;
? ? ? ? ? public double Html;
? ? ? ? ? public double sum;
? ? ? ? ? } ? ? ? ? ? static void Main(string[] args)
? ? ? ? ? {
Console.WriteLine("請輸入學生的個數:");int a = Convert.ToInt32(Console.ReadLine());List<Student> list = new List<Student>();for (int i = 0; i < a; i++){Student s = new Student();Console.WriteLine("請輸入第{0}個學生的姓名:",i+1);s.name = Console.ReadLine();Console.WriteLine("請輸入第{0}個學生的年齡:", i + 1);s.age = Convert.ToInt32(Console.ReadLine());Console.WriteLine("請輸入第{0}個學生的Cshap成績:", i + 1);s.Cshap = Convert.ToDouble(Console.ReadLine());Console.WriteLine("請輸入第{0}個學生的數據庫成績:", i + 1);s.Database = Convert.ToDouble(Console.ReadLine());Console.WriteLine("請輸入第{0}個學生的網頁成績:", i + 1);s.Html = Convert.ToDouble(Console.ReadLine());s.sum = s.Cshap + s.Database + s.Html;list.Add(s);}//排序for (int i = 0; i < list.Count-1; i++){for (int j = 0; j < list.Count - 1 - i; j++){if (list[j].sum <= list[j + 1].sum){Student zj = list[j];list[j] = list[j + 1];list[j + 1] = zj;}}}//輸出 Console.WriteLine("姓名\t年齡\tCshap\t數據庫\t網頁\t總分");foreach (Student data in list){Console.WriteLine(data.name+"\t"+data.age+"\t"+data.Cshap+"\t"+data.Database+"\t"+data.Html+"\t"+data.sum);}
}
?
轉載于:https://www.cnblogs.com/jia520110270/p/4649838.html
總結
以上是生活随笔為你收集整理的15-07-10 结构体-输入学生成绩进行排序的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 暑假集训-搜索
- 下一篇: rotate array 旋转数组