有沒有更簡單的代碼
using System;
using System.Collections.Generic;
using System.Text;
namespace projGetMaxScore
{
??? class Program
??? {
??????? static void Main(string[] args)
??????? {
????????????? object [,] names = new object[8, 2]{
??????????????? {"吳松",89},{"錢東宇",90},{"伏晨",98},{"陳陸",56},{"周蕊",60},{"林日鵬",91},{"何昆",93},{"關欣",85}
??????????? };
??????????? object temp = 0;
??????????? object maxscore = 0;
??????????? object name = null;
??????????? for (int i = 0; i < names.GetLongLength(0); i++)
??????????? {
??????????????? temp = names[i, 1];
??????????????? if ((int)maxscore < (int)temp)
??????????????? {
??????????????????? maxscore = temp;
??????????????????? name = (string)names[i, 0];
??????????????? }
??????????????? else
??????????????? {
??????????????????? continue;
??????????????? }
??????????? }
??????????? Console.Write("分數(shù)最高的是" + name + ",分數(shù)是" + maxscore+",");
??????? }
??? }
}
2018-07-19
string [] name = new string [] { "吳松","錢東宇","伏晨","陳陸","周蕊","林日鵬","何昆","關欣" };
? ? ? ? ? ? int [] branch = new int [] { 89,90,98,56,60,91,93,85};
? ? ? ? ? ? int zuigao = 0;
? ? ? ? ? ? int index = 0;
? ? ? ? ? ? for(int i=0;i<branch.Length;i++){
? ? ? ? ? ? ? ? if(zuigao>branch[i] == false){
? ? ? ? ? ? ? ? ? ? zuigao = branch[i];
? ? ? ? ? ? ? ? ? ? index = i;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? Console.Write("分數(shù)最高的是{0},分數(shù)是{1}",name[index],branch[index]);
2018-09-03
string [] name = new string [] { "吳松","錢東宇","伏晨","陳陸","周蕊","林日鵬","何昆","關欣" };
? ? ? ? ? ? int [] score = new int [] { 89,90,98,56,60,91,93,85};
? ? ? ? ? ? int high = 0;
? ? ? ? ? ? int index = 0;
? ? ? ? ? ? for(int i=0;i<score.Length;i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if(high<score[i])
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? high = score[i];
? ? ? ? ? ? ? ? ? ? index = i;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? Console.WriteLine("分數(shù)最高的是{0},分數(shù)是{1}",name[index],score[index]);
2018-07-31
string [,] test = new string[8,2]{{"吳松","89"},{"錢東宇","90"},{"伏晨","98"},{"陳陸","56"},{"周蕊","60"},{"林日鵬","91"},{"何昆","93"},{"關欣","85"}};
? ? ? ? ? ? int max = 0;
? ? ? ? ? ? int index=0;
? ? ? ? ? ? for (int i=0;i<test.GetLongLength(0);i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if (max<int.Parse(test[i,1]))
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? max=int.Parse(test[i,1]);
? ? ? ? ? ? ? ? ? ? index=i;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? Console.Write("分數(shù)最高的是{0},分數(shù)是{1}",test[index,0],max);
2018-07-31
我把object的聲明改了。使用了兩種做法。
using System;
using System.Collections.Generic;
using System.Text;
namespace projGetMaxScore
{
??? class Program
??? {
??????? static void Main(string[] args)
??????? {
??????????? //第一種方法
????????????? string [,] names = new string[8, 2]{
??????????????? {"吳松","89"},{"錢東宇","90"},{"伏晨","98"},{"陳陸","56"},{"周蕊","60"},{"林日鵬","91"},{"何昆","93"},{"關欣","85"}
??????????? };
??????????? int temp = 0;
??????????? int maxscore = 0;
??????????? string name = null;
??????????? for (int i = 0; i < names.GetLongLength(0); i++)
??????????? {
??????????????? temp = int.Parse(names[i, 1]);
??????????????? if (maxscore < temp)
??????????????? {
??????????????????? maxscore = temp;
??????????????????? name = names[i, 0];
??????????????? }
??????????????? else
??????????????? {
??????????????????? continue;
??????????????? }
??????????? }
??????????? Console.Write("分數(shù)最高的是" + name + ",分數(shù)是" + maxscore+",");
???????????
??????????? //第二種方法索引法。
???????????? string[,] info = new string[8, 2] { { "吳松", "89" }, { "錢東宇", "90" }, { "伏晨", "98" }, { "陳陸", "56" }, { "周蕊", "60" }, { "林日鵬", "9" }, { "何昆", "93" }, { "關欣", "85" } };
????????????? int temp2 = 0;
????????????? for (int i = 0; i < info.GetLongLength(0); i++)
????????????? {
????????????????? if (int.Parse(info[i, 1]) > int.Parse(info[temp2, 1]))
????????????????? {
????????????????????? temp2 = i;
????????????????? }
????????????? }
????????????? Console.Write("分數(shù)最高的是" + info[temp2, 0] + ",分數(shù)是" + info[temp2, 1]);
??????? }
??? }
}
2018-07-25
using System;
using System.Collections.Generic;
using System.Text;
namespace projGetMaxScore
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? string[]names={"吳松","錢東宇","伏晨","陳陸","周蕊","林日鵬","何昆","關欣"};
? ? ? ? ? ? int[]score={89,90,98,56,60,91,93,85};
? ? ? ? ? ? int MAX=score[0];
? ? ? ? ? ? string maxName=names[0];
? ? ? ? ? ? for(int i=0;i<score.Length;i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if(score[i]>MAX)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? MAX=score[i];
? ? ? ? ? ? ? ? maxName=names[i];
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? Console.Write("分數(shù)最高的是{0},分數(shù)是{1}",maxName,MAX);
? ? ? ? }
? ? }
}
2018-07-20
請問為什么要用object?
2018-07-17
好好好