我想要查找整數數組中前3個最大重複數字?若要查找整數數組中前3個最大重複數字
下面是一段代碼,我都試過,但我無法找到期望的結果:
static void Main(string[] args)
{
int[,] numbers = {
{1, 2, 0, 6 },
{5, 6, 7, 0 },
{9, 3, 6, 2 },
{6, 4, 8, 1 }
};
int count = 0;
List<int> checkedNumbers = new List<int>();
foreach (int t in numbers)
{
if (!checkedNumbers.Contains(t))
{
foreach (int m in numbers)
{
if (m == t)
{
count++;
}
}
Console.WriteLine("Number {0} is Repeated {1} Times ", t, count);
count = 0;
checkedNumbers.Add(t);
}
}
Console.ReadLine();
}
我發佈了我試過的代碼。如果我做錯了什麼,只是看一看,並建議我? –
請檢查我的答案與您的代碼 –