CSharp · Console
using System;
public class Program
{
private static int GetCountOfItems(int[,] arr)
{
int res = 0;
for (int i = 0; i < arr.GetLength(0); i++)
{
// для каждой строки находим кол-во элементов arr[i, j]
// таких, что все элементы, стоящие в строке до него, меньше m[i, j]
int item = 0;
for (int j = 0; j < arr.GetLength(1); j++)
{
if (arr[i, j] > item)
{
item = arr[i, j];
res++;
}
}
}
return res;
}
// Функция поворота матрицы по часовой стрелке
private static int[,] RotateMatrix(int[,] arr)
{
int rows = arr.GetLength(0);
int cols = arr.GetLength(1);
int[,] newArr = new int[cols, rows];
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
newArr[j, rows - i - 1] = arr[i, j];
}
}
return newArr;
}
private static int GetAnswer(int[,] arr)
{
int res = 0;
for (int i = 0; i < 4; i++)
{
res += GetCountOfItems(arr);
arr = RotateMatrix(arr);
}
return res;
}
public static void Main()
{
Console.WriteLine("UniLecs");
int[,] arr = new int[3, 4]
{
{ 6, 4, 10, 11 },
{ 2, 9, 9, 3 },
{ 5, 4, 5, 4 }
};
Console.WriteLine("Answer = {0}", GetAnswer(arr)); // 25
}
}