Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- namespace P12.StringMatrixRotation
- {
- class StringMatrixRotation
- {
- private static char[,] matrix;
- static void Main()
- {
- int degrees = int.Parse(Regex.Match(Console.ReadLine(), "[0-9]+").ToString()) % 360;
- var tempList = new List<List<char>>();
- int rows = 0;
- int cols = 0;
- string inputRow;
- while ((inputRow = Console.ReadLine()) != "END")
- {
- if (inputRow.Length > cols)
- {
- cols = inputRow.Length;
- }
- tempList.Add(inputRow.ToList());
- rows++;
- }
- //fill matrix
- matrix = new char[rows, cols];
- for (int r = 0; r < rows; r++)
- {
- for (int c = 0; c < cols; c++)
- {
- try
- {
- matrix[r, c] = tempList[r][c];
- }
- catch (Exception)
- {
- matrix[r, c] = ' ';
- }
- }
- }
- switch (degrees)
- {
- case 90:
- matrix = rotate90degrees(matrix);
- break;
- case 180:
- matrix = rotate90degrees(matrix);
- matrix = rotate90degrees(matrix);
- break;
- case 270:
- matrix = rotate90degrees(matrix);
- matrix = rotate90degrees(matrix);
- matrix = rotate90degrees(matrix);
- break;
- }
- //print
- for (int r = 0; r < matrix.GetLength(0); r++)
- {
- for (int c = 0; c < matrix.GetLength(1); c++)
- {
- Console.Write(matrix[r, c]);
- }
- Console.WriteLine();
- }
- }
- private static char[,] rotate90degrees(char[,] input)
- {
- int rows = input.GetLength(0);
- int cols = input.GetLength(1);
- char[,] output = new char[cols, rows];
- for (int r = 0; r < rows; r++)
- {
- for (int c = 0; c < cols; c++)
- {
- output[c, rows - 1 - r] = input[r, c];
- }
- }
- return output;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment