Advertisement
Guest User

Untitled

a guest
Sep 21st, 2018
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.09 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4.  
  5. namespace _12._String_Matrix_Rotation
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string degreeRotation = Console.ReadLine();
  12.             List<string> inputsText = new List<string>();
  13.  
  14.             string currentRow = Console.ReadLine();
  15.             int maxLength = int.MinValue;
  16.             while(currentRow != "END")
  17.             {
  18.                 inputsText.Add(currentRow);
  19.                 if (currentRow.Length > maxLength)
  20.                 {
  21.                     maxLength = currentRow.Length;
  22.                 }
  23.                 currentRow = Console.ReadLine();
  24.             }
  25.             char[][] matrix = new char[inputsText.Count][];
  26.             for (int row = 0; row < inputsText.Count; row++)
  27.             {
  28.                 int rowLength = inputsText[row].Length;
  29.                 matrix[row] = new char[maxLength];
  30.                 for (int col = 0; col < inputsText[row].Length; col++)
  31.                 {
  32.                     if (col >= maxLength)
  33.                     {
  34.                         matrix[row][col] = ' ';
  35.                     }
  36.                     else
  37.                     {
  38.                         matrix[row][col] = inputsText[row][col];
  39.                     }
  40.                 }
  41.             }
  42.             List<string> final = new List<string>();
  43.             List<string> current = new List<string>();
  44.             final.Clear();
  45.             for (int row = 0; row < inputsText.Count; row++)
  46.             {
  47.                 string inner = "";
  48.                 for (int col = 0; col < maxLength; col++)
  49.                 {
  50.                     inner += matrix[row][col];
  51.                 }
  52.                 current.Add(inner);
  53.             }
  54.             int degrees = int.Parse(Regex.Match(degreeRotation, "[0-9]+").Value);
  55.             int i = degrees % 360;
  56.             int iterations = 0;
  57.             if (i == 90)
  58.             {
  59.                 iterations = 1;
  60.             }
  61.             else if (i == 180)
  62.             {
  63.                 iterations = 2;
  64.             }
  65.             else if (i == 270)
  66.             {
  67.                 iterations = 3;
  68.             }
  69.            
  70.             for (int j = 1; j <= iterations; j++)
  71.             {
  72.                 final = RotateMatrix(current, current.Count, current[0].Length);
  73.                 current = final;
  74.             }
  75.             foreach (var item in current)
  76.             {
  77.                 Console.WriteLine(string.Join("", item));
  78.             }
  79.         }
  80.  
  81.         static List<string> RotateMatrix(List<string> matrix, int rows, int cols)
  82.         {
  83.             List<string> copyMatrix = new List<string>();
  84.             for (int col = 0; col < cols; col++)
  85.             {
  86.                 string inner = "";
  87.                 for (int row = rows - 1; row >= 0; row--)
  88.                 {
  89.                     char value = matrix[row][col];
  90.                     inner += value;
  91.                 }
  92.                 copyMatrix.Add(inner);
  93.             }
  94.             return copyMatrix;
  95.         }
  96.     }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement