我在寻找 int[x,6] 数组中最常见的整数组时遇到问题,其中 x <= 100000。数字在 0 到 50 之间。例如输入。(N = 2)
14 24 44 36 37 45 - here
01 02 06 24 33 44
10 17 34 40 44 45 - here
12 13 28 31 37 47
01 06 07 09 40 45
01 05 06 19 35 44
13 19 20 26 31 47
44 20 30 31 45 46 - here
02 04 14 23 30 34
27 30 41 42 44 49
03 06 15 27 37 48
输出:
44, 45 (3) // appeared 3 times
我试过的附加代码。现在我知道它不起作用,但我被要求发布它。我不只是在没有尝试的情况下寻求帮助。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace TotoLotek
{
class Program
{
static void Main(string[] args)
{
StreamReader czytnik = new StreamReader("dane_wejsciowe.txt");
List<int[]> lista = new List<int[]>();
string linia = "";
while ((linia = czytnik.ReadLine()) != null)
{
string[] numery = linia.Split(' ');
int[] tablica_intow = new int[6];
for (int i = 0; i < 6; i++)
{
tablica_intow[i] = int.Parse(numery[i]);
}
lista.Add(tablica_intow);
}
czytnik.Close();
int[] tablica = new int [50];
for (int i = 0; i< lista.Count(); i++)
{
for (int j = 0; j < 6; j++)
{
tablica[lista[i][j]]++;
}
}
int maks = tablica[0];
int maks_indeks = 0;
for (int i = 0; i < 50; i++)
{
if (tablica[i] > maks)
{
maks = tablica[i];
maks_indeks = i;
}
}
Console.Write("{0}({1}) ", maks_indeks, maks);
List<int[]> lista2 = new List<int[]>();
for (int i = 0; i < lista.Count(); i++)
{
for (int j = 0; j < 6; j++)
{
if (lista[i][j] == maks_indeks)
lista2.Add(lista[i]);
break;
}
}
int[] tablica2 = new int[50];
for (int i = 0; i < lista2.Count(); i++)
{
for (int j = 0; j < 6; j++)
{
tablica2[lista2[i][j]]++;
}
}
int maks2 = tablica2[0];
int maks_indeks2 = 0;
for (int i = 0; i < 50; i++)
{
if (tablica2[i] > maks2 && i != maks_indeks)
{
maks2 = tablica2[i];
maks_indeks2 = i;
}
}
Console.Write("{0}({1}) ", maks_indeks2, maks2);
int xdddd = 2;
}
}
}