| using System;
 using System.Collections.Generic;
 using System.Text;
 namespace shiyan
 {
 struct Student
 {
 public long num;
 public string name;
 public Double scs;
 }
 class Program
 {
 static void Main(string[] args)
 {
 int j, k;
 string str;
 Console.Write("请输入学生人数:");
 str = Console.ReadLine();
 j = int.Parse(str);
 Student[] stu1;
 stu1 = new Student[j];
 for (k = 0; k < j; k++)//给二维数组赋初值
 {
 Console.Write("请输入第{0}位同学的姓名:", k + 1);
 str = Console.ReadLine();
 stu1[k].name = str;
 Console.Write("请输入第{0}位同学的总成绩:", k + 1);
 str = Console.ReadLine();
 stu1[k].scs = double.Parse(str);
 }
 for (int i = 0; i < stu1.Length; i++)//冒泡法排序
 {
 for (int h = i; h < stu1.Length;h++)
 {
 if (stu1[i].scs > stu1[h].scs)
 {
 Student temp = stu1[i];
 stu1[i] = stu1[h];
 stu1[h] = temp;
 }
 }
 }
 foreach (Student temp in stu1)
 {
 Console.WriteLine("姓名:{1},总成绩:{2}", temp.name, temp.scs);
 }
 Console.ReadLine();
 }
 }
 }
 |