課程
/后端開(kāi)發(fā)
/C#
/C#開(kāi)發(fā)輕松入門
名字和分?jǐn)?shù)的數(shù)據(jù)類型這塊兒不好弄啊。。
2018-12-17
源自:C#開(kāi)發(fā)輕松入門 6-1
正在回答
二維數(shù)組這個(gè)題不好弄,你定義string的到時(shí)候分?jǐn)?shù)不好比較,你定義int但名字又是字符串,最好用兩個(gè)數(shù)組分別裝吧,大不了你下標(biāo)對(duì)應(yīng)就好,找出最高分是多少,在遍歷一遍數(shù)組誰(shuí)等于這個(gè)最高分,直接輸出就ok
? ? ? ? ? ? string[,] list = new string[8, 2] {?
? ? ? ? ? ? ? ? { "吳松", "89" },?
? ? ? ? ? ? ? ? { "錢東宇", "90" },?
? ? ? ? ? ? ? ? { "伏晨", "98" },?
? ? ? ? ? ? ? ? { "陳陸", "56" },?
? ? ? ? ? ? ? ? { "周蕊", "60" },?
? ? ? ? ? ? ? ? { "林日鵬", "91" },?
? ? ? ? ? ? ? ? { "何昆", "93" },?
? ? ? ? ? ? ? ? { "關(guān)欣", "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("分?jǐn)?shù)最高的是{0},分?jǐn)?shù)是{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"},{"關(guān)欣","85"}};
? ? ? ? ? ? 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("分?jǐn)?shù)最高的是{0},分?jǐn)?shù)是{1}",score[y,0],score[y,1]);
? ? ? ? }
? ? }
}
舉報(bào)
本門課程是C#語(yǔ)言的入門教程,將帶你輕松入門.NET開(kāi)發(fā)
9 回答請(qǐng)問(wèn)這個(gè)題使用二維數(shù)組怎么做??
1 回答二維數(shù)組
3 回答新手只能寫(xiě)成這樣了,不知道怎么用二維數(shù)組寫(xiě)?
1 回答老師在嗎?用二維數(shù)組還是一維數(shù)組效率比較高呢?我現(xiàn)在用的是二維數(shù)組,代碼如下
2 回答關(guān)于二維數(shù)組GetLength的用法
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2018-12-19
二維數(shù)組這個(gè)題不好弄,你定義string的到時(shí)候分?jǐn)?shù)不好比較,你定義int但名字又是字符串,最好用兩個(gè)數(shù)組分別裝吧,大不了你下標(biāo)對(duì)應(yīng)就好,找出最高分是多少,在遍歷一遍數(shù)組誰(shuí)等于這個(gè)最高分,直接輸出就ok
2019-02-25
? ? ? ? ? ? string[,] list = new string[8, 2] {?
? ? ? ? ? ? ? ? { "吳松", "89" },?
? ? ? ? ? ? ? ? { "錢東宇", "90" },?
? ? ? ? ? ? ? ? { "伏晨", "98" },?
? ? ? ? ? ? ? ? { "陳陸", "56" },?
? ? ? ? ? ? ? ? { "周蕊", "60" },?
? ? ? ? ? ? ? ? { "林日鵬", "91" },?
? ? ? ? ? ? ? ? { "何昆", "93" },?
? ? ? ? ? ? ? ? { "關(guān)欣", "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("分?jǐn)?shù)最高的是{0},分?jǐn)?shù)是{1}", maxname, max);
2019-02-24
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"},{"關(guān)欣","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("分?jǐn)?shù)最高的是{0},分?jǐn)?shù)是{1}",score[y,0],score[y,1]);
? ? ? ? }
? ? }
}