Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- namespace _12._String_Matrix_Rotation
- {
- class Program
- {
- static void Main(string[] args)
- {
- string degreeRotation = Console.ReadLine();
- List<string> inputsText = new List<string>();
- string currentRow = Console.ReadLine();
- int maxLength = int.MinValue;
- while(currentRow != "END")
- {
- inputsText.Add(currentRow);
- if (currentRow.Length > maxLength)
- {
- maxLength = currentRow.Length;
- }
- currentRow = Console.ReadLine();
- }
- char[][] matrix = new char[inputsText.Count][];
- for (int row = 0; row < inputsText.Count; row++)
- {
- int rowLength = inputsText[row].Length;
- matrix[row] = new char[maxLength];
- for (int col = 0; col < inputsText[row].Length; col++)
- {
- if (col >= maxLength)
- {
- matrix[row][col] = ' ';
- }
- else
- {
- matrix[row][col] = inputsText[row][col];
- }
- }
- }
- List<string> final = new List<string>();
- List<string> current = new List<string>();
- final.Clear();
- for (int row = 0; row < inputsText.Count; row++)
- {
- string inner = "";
- for (int col = 0; col < maxLength; col++)
- {
- inner += matrix[row][col];
- }
- current.Add(inner);
- }
- int degrees = int.Parse(Regex.Match(degreeRotation, "[0-9]+").Value);
- int i = degrees % 360;
- int iterations = 0;
- if (i == 90)
- {
- iterations = 1;
- }
- else if (i == 180)
- {
- iterations = 2;
- }
- else if (i == 270)
- {
- iterations = 3;
- }
- for (int j = 1; j <= iterations; j++)
- {
- final = RotateMatrix(current, current.Count, current[0].Length);
- current = final;
- }
- foreach (var item in current)
- {
- Console.WriteLine(string.Join("", item));
- }
- }
- static List<string> RotateMatrix(List<string> matrix, int rows, int cols)
- {
- List<string> copyMatrix = new List<string>();
- for (int col = 0; col < cols; col++)
- {
- string inner = "";
- for (int row = rows - 1; row >= 0; row--)
- {
- char value = matrix[row][col];
- inner += value;
- }
- copyMatrix.Add(inner);
- }
- return copyMatrix;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement