这道题如果用二维数组的话该怎么作?
名字和分数的数据类型这块儿不好弄啊。。
名字和分数的数据类型这块儿不好弄啊。。
2018-12-17
string[,] list = new string[8, 2] {
{ "吴松", "89" },
{ "钱东宇", "90" },
{ "伏晨", "98" },
{ "陈陆", "56" },
{ "周蕊", "60" },
{ "林日鹏", "91" },
{ "何昆", "93" },
{ "关欣", "85" }
};
int max = 0;
string maxname = "吴松";
for (int i = 0; i < list.GetLength(0); i++)
{
if (int.Parse(list[i, 1]) > max)
{
max = int.Parse(list[i, 1]);
maxname = list[i, 0];
}
}
Console.WriteLine("分数最高的是{0},分数是{1}", maxname, max);
using System;
using System.Collections.Generic;
using System.Text;
namespace Test
{
class Program
{
static void Main(string[] args)
{
string[,] score = new string[,] {{"吴松","89"},{"钱东宇","90"},{"伏晨","98"},{"陈陆","56"},{"周蕊","60"}, {"林日鹏","91" },{"何昆","93"},{"关欣","85"}};
int max = 0;
int y = 0;
for (int x = 0;x < score.GetLength(0); x++ )
{
if (Convert.ToInt32(score[x, 1]) >max)
{
max = (Convert.ToInt32(score[x, 1]));
y = x;
}
}
Console.WriteLine("分数最高的是{0},分数是{1}",score[y,0],score[y,1]);
}
}
}
举报