Проверка на совпадение элементов строки, столбца - C#
Формулировка задачи:
TEST(a, k) принимает значение true, если все элементы k-й строки совпадают с элементами к-го столбца.
пока что есть для одного элемента
static bool test (int [,]mas,bool a)
{
Console.WriteLine("проверка строки:");
int k = int.Parse(Console.ReadLine());
for (int i=0;i<mas.GetLength(0);i++)
{
for (int j = 0; j < mas.GetLength(1); j++)
{
if (mas[k, j] == mas[i, k])
a = true;
}
}
return a;
}static bool test (int [,]mas,bool a)
{
Console.WriteLine("проверка строки:");
int k = int.Parse(Console.ReadLine());
int[] linearray = new int[mas.Length];
int[] columnarray = new int[mas.Length];
for (int i=0;i<mas.GetLength(0);i++)
{
for (int j = 0; j < mas.GetLength(1); j++)
{
linearray[j] = mas[k,j];
columnarray[i] = mas[i,k];
}
}
if (linearray == columnarray)
a = true;
return a;
}Решение задачи: «Проверка на совпадение элементов строки, столбца»
textual
Листинг программы
static bool Test(int[,] a, int k)
{
if (a.GetLength(0) != a.GetLength(1)) return false;
for (int i = 0; i < a.GetLength(0); i++)
if (a[k, i] != a[i, k])
return false;
return true;
}