有一个整数序列,我必须在其中找到重复次数最多的值。如果有许多重复值,请找到所有重复值中的最小值。
示例:如果是 {-10,17,13,17,-10,21},则结果为 -10
到目前为止我已经走了多远:
static void YL2()
{
Random random = new Random();
int mitu = 10, minv = 0, maxv = 20;
int[] mas1 = new int[mitu];
int i;
int lowest;
for (i = 0; i < mitu; i++) mas1[i] = random.Next(minv, maxv);
for (i = 0; i < mitu; i++)
Console.Write("{0,4}", mas1[i]);
Console.Write("\n\n");
int count = 0;
List<int> checkedNumbers = new List<int>();
foreach (int t in mas1)
{
if (!checkedNumbers.Contains(t))
{
foreach (int m in mas1)
{
if (m == t)
{
count++;
}
}
Console.WriteLine("Number {0} is repeated {1} times", t, count);
count = 0;
checkedNumbers.Add(t);
}
}
for (lowest = mas1[0], i = 1; i < mitu; i++)
{
if (mas1[i] < lowest) lowest = mas1[i];
}
Console.Write("Lowest value is {0}\n\n", lowest);
}