1、输入班级人数,输入每个人的姓名、语数英成绩进入集合
求语文的总分,数学的平均分,
英语的最高分的人的姓名及所有科目的分数(冒泡排序)
0 姓名 4 8 12
1 语文成绩5 9 13
2 数学成绩6 10 14
3 英语成绩7 11 15
//数字为索引号
Console.Write("请输入班级人数:");
int n = int.Parse(Console.ReadLine());
double yu = 0;
double shu = 0;
ArrayList al = new ArrayList();
for (int i = 0; i < n; i++)
{
Console.Write("请输入第{0}个人的姓名:",i+1);
al.Add(Console.ReadLine());
Console.Write("请输入第{0}个人的语文成绩:",i+1);
al.Add(double.Parse(Console.ReadLine()));
yu += double.Parse(al[al.Count - 1].ToString());
Console.Write("请输入第{0}个人的数学成绩:", i + 1);
al.Add(double.Parse(Console.ReadLine()));
shu += double.Parse(al[al.Count - 1].ToString());
Console.Write("请输入第{0}个人的英语成绩:", i + 1);
al.Add(double.Parse(Console.ReadLine()));
}
Console.WriteLine("所有信息输入完毕,请按回车键继续!");
Console.ReadLine();
Console.WriteLine("语文的总分是:"+yu);
Console.WriteLine("数学的平均分是:"+(shu/n));
for (int i = 3; i < 4*n-1; i+=4)
{
for (int j = i; j < 4 * n - 4; j += 4)
{
if (double.Parse(al[i].ToString()) < double.Parse(al[j + 4].ToString()))
{
//换姓名
object zhong = al[i - 3];
al[i - 3] = al[j + 1];
al[j + 1] = zhong;
//换语文
zhong = al[i - 2];
al[i - 2] = al[j + 2];
al[j + 2] = zhong;
//换数学
zhong = al[i - 1];
al[i - 1] = al[j + 3];
al[j + 3] = zhong;
//换英语
zhong = al[i];
al[i] = al[j + 4];
al[j + 4] = zhong;
}
}
}
Console.WriteLine("英语最高分的学生是{0},英语分数是{1},语文分数是{2},数学分数{3}",al[0],al[3],al[1],al[2]);
Console.ReadLine();