using System;
using System.Linq;
class GFG {
static void reverse(int [,]arr, int N, int M)
{
// Traverse each row of [,]arr
for (int i = 0; i < M; i++) {
// Initialise start and end index
int start = 0;
int end = N - 1;
// Till start < end, swap the element
// at start and end index
while (start < end) {
// Swap the element
int temp = arr[i,start];
arr[i, start] = arr[i, end];
arr[i, end] = temp;
// Increment start and decrement
// end for next pair of swapping
start++;
end--;
}
}
}
// Function to check if two matrices
// are equal or not
static bool isEqual(int [,] arr, int [,] brr, int n, int m)
{
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (arr[i,j] != brr[i,j])
return false;
}
}
return true;
}
// Function to rotate matrix by 90 degrees clockwise
static void rotate(int [,] arr, int n, int m)
{
for (int i = 0; i < n; i++)
for (int j = 0; j < i; j++)
{
int curr = arr[i,j];
arr[i,j] = arr[j,i];
arr[j,i] = curr;
}
reverse(arr,n,m);
}
// Find Minimum rotation to reach the desired matrix
static void findRotation(int [,] arr, int [,] brr, int n, int m)
{
if (isEqual(arr, brr, n, m)) {
Console.Write(0);
return;
}
for (int i = 1; i < 4; i++) {
// Rotate by 90 degrees clockwise
rotate(arr,n,m);
// Checking if both arr[][] and brr[]
// are now equal or not
if (isEqual(arr, brr,n,m)) {
if (i < 4 - i) {
Console.Write( "+" + i);
}
else
Console.Write("-" + (4 - i));
return;
}
}
// If converting brr[][] is not possible
Console.Write("NA");
}
/* Driver program to test above
functions */
public static void Main()
{
int [,] arr = new int[,] { { 2, 3 }, { 4, 5 } };
int [,] brr = new int[,] { { 4, 2 }, { 5, 3 } };
int N = 2;
int M = 2;
// Function Call
findRotation(arr, brr, N, M);
}
}
// This code is contributed by Aarti_Rathi