課程
/后端開發(fā)
/C#
/C#開發(fā)輕松入門
6-1中的習(xí)題如果加上語(yǔ)數(shù)外三個(gè)科目每個(gè)學(xué)生的成績(jī)表該如何編寫,望大神告知一二!
2018-09-17
源自:C#開發(fā)輕松入門 6-1
正在回答
using System;
using System.Collections.Generic;
using System.Text;
namespace projGetMaxScore
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? //語(yǔ)數(shù)外三科 可以用二維數(shù)組來(lái)寫
? ? ? ? ? ?//{{語(yǔ)文成績(jī),數(shù)學(xué)成績(jī),英語(yǔ)成績(jī)}}
? ? ? ? ? ? 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("語(yǔ)文分?jǐn)?shù)最高的是{0},分?jǐn)?shù)是{1},", MaxName, Max); continue;
? ? ? ? ? ? ?case 1 : Console.WriteLine("數(shù)學(xué)分?jǐn)?shù)最高的是{0},分?jǐn)?shù)是{1},", MaxName, Max);? continue;?
? ? ? ? ? ? ?case 2 : Console.WriteLine("英語(yǔ)分?jǐn)?shù)最高的是{0},分?jǐn)?shù)是{1},", MaxName, Max); continue;? ? ? ? ? ?
? ? ? ? ?}
? ? ? ? ? ? }? ? ??
? ? ? ? ? ? Console.ReadKey();? ?
? ? ? ? }
? ? }
}
//減少?gòu)?fù)雜性
using System.Linq;
using System.Threading.Tasks;
namespace test
? ? public class Program
? ? ? ? public static void Main(string[] args)
? ? ? ? ? ? //語(yǔ)數(shù)外三科 可以用二維數(shù)組來(lái)寫
? ? ? ? ? ? //{{語(yǔ)文成績(jī),數(shù)學(xué)成績(jī),英語(yǔ)成績(jī)}}
? ? ? ? ? ? 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("語(yǔ)文分?jǐn)?shù)最高的是{0},分?jǐn)?shù)是{1},", MaxChineseName, MaxChinese);
? ? ? ? ? ? for (int j = 0; j < 5; j++)
? ? ? ? ? ? ? ? if (score[j,1] > MaxMath)
? ? ? ? ? ? ? ? ? ? MaxMath = score[j,1];
? ? ? ? ? ? ? ? ? ? MaxMathName = name[j];
? ? ? ? ? ? Console.WriteLine("數(shù)學(xué)分?jǐn)?shù)最高的是{0},分?jǐn)?shù)是{1},", MaxMathName, MaxMath);
? ? ? ? ? ? for (int k = 0; k < 5; k++)
? ? ? ? ? ? ? ? if (score[k,2] > MaxEnglish)
? ? ? ? ? ? ? ? ? ? MaxEnglish = score[k,2];
? ? ? ? ? ? ? ? ? ? MaxEnglishName = name[k];
? ? ? ? ? ? Console.WriteLine("英語(yǔ)分?jǐn)?shù)最高的是{0},分?jǐn)?shù)是{1},", MaxEnglishName, MaxEnglish);
? ? ? ? ? ? Console.ReadKey();
寫的比較冗余,期待有誰(shuí)貼出更精簡(jiǎn)的代碼, 共同學(xué)習(xí)一下 謝謝。
慕仔4095262 提問(wèn)者
舉報(bào)
本門課程是C#語(yǔ)言的入門教程,將帶你輕松入門.NET開發(fā)
2 回答如何做一個(gè)學(xué)生查詢成績(jī)的程序
3 回答這道題如果用二維數(shù)組的話該怎么作?
2 回答求救大神如何使用C#輸入兩個(gè)正整數(shù),求他們的最小公倍數(shù)?
1 回答如何在.gz的壓縮文件中生成一個(gè)空白的.inf文件
3 回答該代碼如何寫呢?請(qǐng)幫幫我.
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2018-09-25
using System;
using System.Collections.Generic;
using System.Text;
namespace projGetMaxScore
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? //語(yǔ)數(shù)外三科 可以用二維數(shù)組來(lái)寫
? ? ? ? ? ?//{{語(yǔ)文成績(jī),數(shù)學(xué)成績(jī),英語(yǔ)成績(jī)}}
? ? ? ? ? ? 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("語(yǔ)文分?jǐn)?shù)最高的是{0},分?jǐn)?shù)是{1},", MaxName, Max); continue;
? ? ? ? ? ? ?case 1 : Console.WriteLine("數(shù)學(xué)分?jǐn)?shù)最高的是{0},分?jǐn)?shù)是{1},", MaxName, Max);? continue;?
? ? ? ? ? ? ?case 2 : Console.WriteLine("英語(yǔ)分?jǐn)?shù)最高的是{0},分?jǐn)?shù)是{1},", MaxName, Max); continue;? ? ? ? ? ?
? ? ? ? ?}
? ? ? ? ? ? }? ? ??
? ? ? ? ? ? Console.ReadKey();? ?
? ? ? ? }
? ? }
}
//減少?gòu)?fù)雜性
2018-09-18
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)
? ? ? ? {
? ? ? ? ? ? //語(yǔ)數(shù)外三科 可以用二維數(shù)組來(lái)寫
? ? ? ? ? ? //{{語(yǔ)文成績(jī),數(shù)學(xué)成績(jī),英語(yǔ)成績(jī)}}
? ? ? ? ? ? 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("語(yǔ)文分?jǐn)?shù)最高的是{0},分?jǐn)?shù)是{1},", MaxChineseName, MaxChinese);
? ? ? ? ? ? for (int j = 0; j < 5; j++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if (score[j,1] > MaxMath)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? MaxMath = score[j,1];
? ? ? ? ? ? ? ? ? ? MaxMathName = name[j];
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? Console.WriteLine("數(shù)學(xué)分?jǐn)?shù)最高的是{0},分?jǐn)?shù)是{1},", MaxMathName, MaxMath);
? ? ? ? ? ? for (int k = 0; k < 5; k++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if (score[k,2] > MaxEnglish)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? MaxEnglish = score[k,2];
? ? ? ? ? ? ? ? ? ? MaxEnglishName = name[k];
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? Console.WriteLine("英語(yǔ)分?jǐn)?shù)最高的是{0},分?jǐn)?shù)是{1},", MaxEnglishName, MaxEnglish);
? ? ? ? ? ? Console.ReadKey();
? ? ? ? }
? ? }
}
寫的比較冗余,期待有誰(shuí)貼出更精簡(jiǎn)的代碼, 共同學(xué)習(xí)一下 謝謝。