慕仔4095262
2018-09-17 21:59
6-1中的习题如果加上语数外三个科目每个学生的成绩表该如何编写,望大神告知一二!
using System;
using System.Collections.Generic;
using System.Text;
namespace projGetMaxScore
{
class Program
{
static void Main(string[] args)
{
//语数外三科 可以用二维数组来写
//{{语文成绩,数学成绩,英语成绩}}
int[,] score = new int[5,3]{ {98,88,95 },{80,60,56}, {75,40,90 }, {68,50,23}, {82,100,85} };
string[] name = new string[] { "1吴松", "2钱东宇", "3伏晨", "4陈陆", "5周蕊"};
for(int j=0;j<3;j++)
{
int Max= 0;
string MaxName = null;
for (int i = 0; i < 5; i++)
{
if (score[i,j] > Max)
{
Max = score[i,j];
MaxName = name[i];
}
}
switch(j)
{
case 0 : Console.WriteLine("语文分数最高的是{0},分数是{1},", MaxName, Max); continue;
case 1 : Console.WriteLine("数学分数最高的是{0},分数是{1},", MaxName, Max); continue;
case 2 : Console.WriteLine("英语分数最高的是{0},分数是{1},", MaxName, Max); continue;
}
}
Console.ReadKey();
}
}
}
//减少复杂性
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace test
{
public class Program
{
public static void Main(string[] args)
{
//语数外三科 可以用二维数组来写
//{{语文成绩,数学成绩,英语成绩}}
int[,] score = new int[5,3]{ {98,88,95 },{80,60,56}, {75,40,90 }, {68,50,23}, {82,100,85} };
string[] name = new string[] { "1吴松", "2钱东宇", "3伏晨", "4陈陆", "5周蕊"};
int MaxChinese = 0;
int MaxMath = 0;
int MaxEnglish = 0;
string MaxChineseName = null;
string MaxMathName = null;
string MaxEnglishName = null;
for (int i = 0; i < 5; i++)
{
if (score[i,0] > MaxChinese)
{
MaxChinese = score[i,0];
MaxChineseName = name[i];
}
}
Console.WriteLine("语文分数最高的是{0},分数是{1},", MaxChineseName, MaxChinese);
for (int j = 0; j < 5; j++)
{
if (score[j,1] > MaxMath)
{
MaxMath = score[j,1];
MaxMathName = name[j];
}
}
Console.WriteLine("数学分数最高的是{0},分数是{1},", MaxMathName, MaxMath);
for (int k = 0; k < 5; k++)
{
if (score[k,2] > MaxEnglish)
{
MaxEnglish = score[k,2];
MaxEnglishName = name[k];
}
}
Console.WriteLine("英语分数最高的是{0},分数是{1},", MaxEnglishName, MaxEnglish);
Console.ReadKey();
}
}
}
写的比较冗余,期待有谁贴出更精简的代码, 共同学习一下 谢谢。
C#开发轻松入门
254118 学习 · 1459 问题
相似问题