标签:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace jiegouti2 { class Program { struct student { public string xuehao; public string xingming; public decimal fenshu; } static void Main(string[] args) { Console.WriteLine("欢迎使用学生分数管理系统!"); Console.WriteLine("请输入学生人数"); int shu = int.Parse(Console.ReadLine()); student[] shuzu = new student[shu]; decimal sum = 0; for (int m = 0; m < shu; m++) { Console.WriteLine("请输入第{0}个学生的\n学号、姓名、C语言分数", m + 1); string a = Console.ReadLine(); string[] b = a.Split(new char[] { ‘\t‘ }); shuzu[m].xuehao = b[0]; shuzu[m].xingming = b[1]; shuzu[m].fenshu = decimal.Parse(b[2]); sum += shuzu[m].fenshu; } for (int m = 0; m < shu-1; m++) { for (int n = m+1; n < shu; n++) { if (shuzu[m].fenshu < shuzu[n].fenshu) { student zhong = new student(); zhong = shuzu[n]; shuzu[n] = shuzu[m]; shuzu[m] = zhong; } } } Console.WriteLine("总分是:{0}", sum); Console.WriteLine("平均分是:{0}", sum / shu); Console.WriteLine("最高分是学号{0}姓名{1}的{2}分", shuzu[0].xuehao.ToString(), shuzu[0].xingming.ToString(), shuzu[0].fenshu.ToString()); Console.WriteLine("最低分是学号{0}姓名{1}的{2}分", shuzu[shu - 1].xuehao.ToString(), shuzu[shu - 1].xingming.ToString(), shuzu[shu - 1].fenshu.ToString()); Console.WriteLine("降序排列为:\n名次\t学号\t姓名\t分数"); for (int m = 0; m < shu; m++) { Console.WriteLine((m+1)+"\t"+shuzu[m].xuehao + "\t" + shuzu[m].xingming + "\t" + shuzu[m].fenshu); } Console.ReadLine(); } } }
效果如下图所示:
标签:
原文地址:http://www.cnblogs.com/XMH1217423419/p/4306252.html