亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

6-1中的習題如果加上語數外三個科目的成績表該如何編寫,望大神告知一二!

6-1中的習題如果加上語數外三個科目每個學生的成績表該如何編寫,望大神告知一二!

正在回答

2 回答

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();? ?

? ? ? ? }

? ? }

}

//減少復雜性

0 回復 有任何疑惑可以回復我~

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();

? ? ? ? }

? ? }

}

寫的比較冗余,期待有誰貼出更精簡的代碼, 共同學習一下 謝謝。

0 回復 有任何疑惑可以回復我~
#1

慕仔4095262 提問者

正在入門階段感謝受教
2018-09-20 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

6-1中的習題如果加上語數外三個科目的成績表該如何編寫,望大神告知一二!

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號