Advertisement
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;
- using System.Threading.Tasks;
- namespace StringMatrixRotation
- {
- class StartUp
- {
- static void Main()
- {
- string[] rotation = Console.ReadLine().Split(new char[] { '(' , ')'},
- StringSplitOptions.RemoveEmptyEntries).ToArray();
- int rotateDegree = int.Parse(rotation[1]);
- List<string> words = new List<string>();
- while (true)
- {
- string input = Console.ReadLine();
- if (input == "END") break;
- words.Add(input);
- }
- int maxLength = words.Max(v => v.Length);
- char[][] jaggedArray = new char[words.Count][];
- FillMatrix(words, maxLength, jaggedArray);
- RotateMatrix(ref jaggedArray, maxLength, rotateDegree);
- PrintMatrix(jaggedArray);
- }
- private static void PrintMatrix(char[][] jaggedArray)
- {
- foreach (var array in jaggedArray)
- {
- Console.WriteLine(string.Join("", array));
- }
- }
- private static void RotateMatrix(ref char[][] jaggedArray,int maxLength, int rotateDegree)
- {
- int rotation = rotateDegree / 90;
- for (int i = 0; i < rotation; i++)
- {
- if (i % 2 == 0)
- {
- int index = 0;
- char[][] tempArray = new char[maxLength][];
- for (int k = 0, x = 0; k < maxLength; k++, x++)
- {
- tempArray[x] = new char[jaggedArray.Length];
- for (int j = 0, z = jaggedArray.Length - 1; j < jaggedArray.Length; j++, z--)
- {
- tempArray[x][j] = jaggedArray[z][index];
- }
- index++;
- }
- jaggedArray = tempArray;
- }
- else
- {
- char[][] tempArray = new char[jaggedArray[0].Length][];
- int index = 0;
- for (int k = 0; k < jaggedArray[0].Length; k++)
- {
- tempArray[k] = new char[maxLength];
- for (int l = jaggedArray.Length- 1, z = 0 ; l >= 0; l--, z++)
- {
- tempArray[k][z] = jaggedArray[l][index];
- }
- index++;
- }
- jaggedArray = tempArray;
- }
- }
- }
- private static void FillMatrix(List<string> words, int maxLength, char[][] jaggedArray)
- {
- for (int i = 0; i < jaggedArray.Length; i++)
- {
- jaggedArray[i] = new char[maxLength];
- char[] wordInChars = words[i].ToCharArray();
- for (int k = 0; k < jaggedArray[i].Length; k++)
- {
- if (wordInChars.Length > k)
- {
- jaggedArray[i][k] = wordInChars[k];
- }
- else
- {
- jaggedArray[i][k] = ' ';
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement