課程
/后端開發
/C#
/C#開發輕松入門
6-1中的習題如果加上語數外三個科目每個學生的成績表該如何編寫,望大神告知一二!
2018-09-17
源自:C#開發輕松入門 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.Linq;
using System.Threading.Tasks;
namespace test
? ? public class Program
? ? ? ? public static void Main(string[] args)
? ? ? ? ? ? //語數外三科 可以用二維數組來寫
? ? ? ? ? ? //{{語文成績,數學成績,英語成績}}
? ? ? ? ? ? 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();
寫的比較冗余,期待有誰貼出更精簡的代碼, 共同學習一下 謝謝。
慕仔4095262 提問者
舉報
本門課程是C#語言的入門教程,將帶你輕松入門.NET開發
2 回答如何做一個學生查詢成績的程序
3 回答這道題如果用二維數組的話該怎么作?
2 回答求救大神如何使用C#輸入兩個正整數,求他們的最小公倍數?
1 回答如何在.gz的壓縮文件中生成一個空白的.inf文件
3 回答該代碼如何寫呢?請幫幫我.
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2018-09-25
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();? ?
? ? ? ? }
? ? }
}
//減少復雜性
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)
? ? ? ? {
? ? ? ? ? ? //語數外三科 可以用二維數組來寫
? ? ? ? ? ? //{{語文成績,數學成績,英語成績}}
? ? ? ? ? ? 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();
? ? ? ? }
? ? }
}
寫的比較冗余,期待有誰貼出更精簡的代碼, 共同學習一下 謝謝。