using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace test06_1
{
class Program
{
static void Main(string[] args)
{
// string[,] score = new string[8, 2] { { "吳松", "89" }, { "錢東宇", "90" }, { "伏晨", "98" }, { "陳璐", "56" }, { "周瑞", "60" }, { "林日鵬", "91" }, { "何晶", "93" }, { "關欣", "85" } };
string[] name = new string[]{ "吳松", "錢東宇", "伏晨", "陳璐", "周蕊", "林日鵬", "何晶", "關欣" };
int[] scores = new int[] { 89,90,98,56,60,91,93,85};
int score = scores[0];
int j = 0;
for (int i = 0; i < scores.Length; i++) {
if (scores[i] > score) {
score = scores[i];
j = i;
}
}
Console.WriteLine("分數最高的是{0},分數為{1}", name[j], score);
}
}
}
uj5u.com熱心網友回復:
是什么問題?你完全沒說嘛還有這里是腳本語言,C#不是
看邏輯,應該是能實作
uj5u.com熱心網友回復:
按照你的程式代碼,怎樣實作二維陣列的排序,就比如從高到底輸出分數和名字排序!uj5u.com熱心網友回復:
先生,您發錯區了,這里是腳本語言(Perl/Python)區
uj5u.com熱心網友回復:
你應該考慮到有多個學生有相同的最高值:
string[] name = new string[] { "吳松", "錢東宇", "伏晨", "陳璐", "周蕊", "林日鵬", "何晶", "關欣" };
int[] scores = new int[] { 89, 90, 98, 56, 60, 91, 93, 98 };
int maxScore = scores.Max();
var v = scores.ToList().Select((item, index) => new { index, item }).ToList();
var indexs = v.Where(a => a.item == maxScore ).Select(a => a.index).ToList();
Console.WriteLine("max:" + maxScore);
foreach (var index in indexs )
{
Console.WriteLine(" " + index + " " + name[index]);
}
uj5u.com熱心網友回復:
string[,] scoreArray = new string[8, 2] { { "吳松", "89" }, { "錢東宇", "90" }, { "伏晨", "98" }, { "陳璐", "56" }, { "周瑞", "60" }, { "林日鵬", "91" }, { "何晶", "93" }, { "關欣", "98" } };
List<int> scores = new List<int>();
for (int i = 0; i < scoreArray.GetLength(0) ; i++)
{
scores.Add( Convert.ToInt32( scoreArray[i, 1]));
}
int maxScore = scores.Max();
var v = scores.ToList().Select((item, index) => new { index, item }).ToList();
var indexs = v.Where(a => a.item == maxScore).Select(a => a.index).ToList();
Console.WriteLine("max:" + maxScore);
foreach (var index in indexs)
{
Console.WriteLine(" " + index + " " + scoreArray[index,0]);
}
uj5u.com熱心網友回復:
邏輯對著,感覺差點東西,萌新混分,順帶膜拜大佬uj5u.com熱心網友回復:
你發這個是想說明什么?uj5u.com熱心網友回復:
string[] name = new string[] { "吳松", "錢東宇", "伏晨", "陳璐", "周蕊", "林日鵬", "何晶", "關欣" };
int[] scores = new int[] { 89, 90, 98, 56, 60, 91, 93, 85 };
int max = scores[0];
int maxIndex = -1;
for (int i = 0; i < scores.Length; i++)
{
if (max < scores[i])
{
max = scores[i];
maxIndex = i;
}
}
Console.WriteLine("分數最高的是{0},分數為{1}", name[maxIndex], max);
uj5u.com熱心網友回復:
寫博客右上角
uj5u.com熱心網友回復:
遍歷,記錄最大分數的人這個想法不錯但是,有分數相同的就嘿嘿了。
看到排分,第一個想到的就是桶排序:
dim name=new string(){ "吳松", "錢東宇", "伏晨", "陳璐", "周蕊", "林日鵬", "何晶", "關欣" }
dim scores=new integer(){ 89, 90, 98, 56, 60, 91, 93, 85 }
dim Test06(100) as string '假定最高分100分
for i as integer = 0 to name.lenght-1
curScores=scores(i)
Test06(curScores) &=name(curScores) & " "
next
for i as integer = Test06.lenght-1 to 0 step -1
if Test06(i)<>Steing.Empty then
debug.print("最高分:" & i & " " & Test06(i)
exit for
end if
next
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/102010.html
標籤:C#
