好像哪里不對(已解決)
已經(jīng)自己更改好了,嘿嘿。
using System;
using System.Collections.Generic;
using System.Text;
namespace projGetMaxScore
{
??? class Program
??? {
??????? static void Main(string[] args)
??????? {
??????????? //聲明string數(shù)組。
??????????? string[,] S = new string[8, 2] { { "吳松", "89" }, { "錢東宇", "90" }, { "伏晨", "98" }, { "陳陸", "56" }, { "周蕊", "60" }, { "林日鵬", "91" }, { "何昆", "93" }, { "關(guān)欣", "85" } };
??????????? //聲明緩存數(shù)組。
??????????? string[] C = new string[2];
??????????? //for循環(huán).
??????????? for (int i = 0; i < S.GetLongLength(0); i++)
??????????? {
??????????????? //緩存數(shù)組與string數(shù)組元素轉(zhuǎn)換為int型.
??????????????? int a = Convert.ToInt32(C[1]);
??????????????? int b = Convert.ToInt32(S[i,1]);
??????????????? //與緩存數(shù)組循環(huán)比較大小.
??????????????? if (a < b)
??????????????? {
??????????????????? //最大值賦值給緩存數(shù)組。
??????????????????? C[0] = S[i, 0];
??????????????????? //賦值前轉(zhuǎn)換回string.
??????????????????? C[1] = Convert.ToString(a);
??????????????????? S[i, 1] = Convert.ToString(b);
??????????????????? C[1] = S[i, 1];
??????????????? }
??????????????? else
??????????????????? continue;
??????????? }
??????????????? //輸出
?????????????????? Console.Write("分?jǐn)?shù)最高的是" + C[0] +","+ "分?jǐn)?shù)是" + C[1]);
??????? }
??? }
}
我寫得好像有點(diǎn)太冗余了。
2016-04-25
using System;
namespace ConsoleApplication2
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? string[] names = new string[8] { "吳松","錢東宇", "伏晨", "陳陸", "周蕊","林日鵬", "何昆", ?"關(guān)欣" };//聲明names數(shù)組
? ? ? ? ? ? int[] score = new int[8] { 89, 90, 98, 56, 60, 91, 93, 85 };//聲明score數(shù)組
? ? ? ? ? ? int max = 0;//聲明最高分,默認(rèn)值為0
? ? ? ? ? ? int j = 0 ;//聲明j,j是表示最高分的索引
????????????//用循環(huán)求出最高分max
? ? ? ? ? ? for (int i = 0; i < names.Length; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if(max<score[i])
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? max=score[i];
? ? ? ? ? ? ? ? ? ? j=i;//將最高分的索引賦值給j
? ? ? ? ? ? ? ? }}
? ? ? ? ? ? Console.Write("分?jǐn)?shù)最高的是"+names[j]+",分?jǐn)?shù)是"+max);
? ? ? ? ? ? }}}
? ? 用分兩組的方法比較簡單 而且更加明了