Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Program
- {
- static void Main()
- {
- var inputString = Console.ReadLine().Split();
- int n = int.Parse(inputString[0]);
- char direction = inputString[1].First();
- long[,] matrix = new long[n, n];
- for (int i = 0; i < n; i++)
- {
- string[] row = Console.ReadLine().Split();
- for (int j = 0; j < n; j++)
- {
- matrix[i, j] = long.Parse(row[j]);
- }
- }
- if (direction == 'L')
- RotateMatrixLeft(matrix, n);
- else
- RotateMatrixRight(matrix, n);
- }
- static void RotateMatrixRight(long[,] matrix, int n)
- {
- var operationList = new List<string>();
- for (int i = 0; i < n / 2; i++)
- {
- for (int j = i; j < n - i - 1; j++)
- {
- int x1 = i, y1 = j;
- int x2 = j, y2 = n - 1 - i;
- int x3 = n - 1 - i, y3 = n - 1 - j;
- int x4 = n - 1 - j, y4 = i;
- operationList.Add(Swap(matrix, x1, y1, x2, y2));
- operationList.Add(Swap(matrix, x2, y2, x3, y3));
- operationList.Add(Swap(matrix, x3, y3, x4, y4));
- }
- }
- Console.WriteLine(operationList.Count);
- foreach (var op in operationList)
- {
- Console.WriteLine(op);
- }
- }
- static void RotateMatrixLeft(long[,] matrix, int n)
- {
- var operationList = new List<string>();
- for (int i = 0; i < n / 2; i++)
- {
- for (int j = i; j < n - i - 1; j++)
- {
- int x1 = i, y1 = j;
- int x2 = j, y2 = n - 1 - i;
- int x3 = n - 1 - i, y3 = n - 1 - j;
- int x4 = n - 1 - j, y4 = i;
- operationList.Add(Swap(matrix, x1, y1, x4, y4));
- operationList.Add(Swap(matrix, x4, y4, x3, y3));
- operationList.Add(Swap(matrix, x3, y3, x2, y2));
- }
- }
- Console.WriteLine(operationList.Count);
- foreach (var op in operationList)
- {
- Console.WriteLine(op);
- }
- }
- static string Swap(long[,] matrix, int x1, int y1, int x2, int y2)
- {
- (matrix[x1, y1], matrix[x2, y2]) = (matrix[x2, y2], matrix[x1, y1]);
- return $"{x1} {y1} {x2} {y2}";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement