Дана целочисленная матрица размера M x N. Найти количество ее строк 1| столбцов 2, все элементы которых различны.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Class1
{
static void Main(string[] args)
{
int m,n, i, j,k,kol;
bool f;
Console.Write("Введите m->");
m = int.Parse(Console.ReadLine());
Console.Write("Введите n->");
n = int.Parse(Console.ReadLine());
int[,] a = new int[n, n];
Console.WriteLine("Исходная матрица");
for ( i=0;i<m;i++)
{
for ( j = 0; j < n; j++)
{
Console.Write("a[{0},{1}]=",i,j);
a[i, j] = int.Parse(Console.ReadLine());
}
Console.WriteLine();
}
///
kol= 0;
for (i = 0; i < m; i++)
{
f = true;
j = 0;
while ((j < n) && f) {
k = 0;
while ((k < n) && f)
if ((a[i, k] == a[i, j]) && (j != k)) f = false;
else k++;
if (f) j++;
}
if (f) kol++;
}
Console.WriteLine("Количество строк, в которых все элементы разные = {0}", kol);
///столбец
kol= 0;
for (j = 0; j < n; j++) {
f = true;
i = 0;
while ((i < m) && f) {
k = 0;
while ((k < m) && f)
if ((a[i, j] == a[k, j]) && (i != k) ) f = false;
else k++;
if (f) i++;
}
if (f) kol++;
}
Console.WriteLine("Количество столбцов, в которых все элементы разные = {0}", kol);
Console.ReadLine();
}
}
}
