SHOW:
|
|
- or go back to the newest paste.
1 | namespace StringMatrixRotation | |
2 | { | |
3 | using System; | |
4 | using System.Collections.Generic; | |
5 | using System.Linq; | |
6 | using System.Text.RegularExpressions; | |
7 | ||
8 | public class StringMatrixRotation | |
9 | { | |
10 | public static void Main() | |
11 | { | |
12 | string degreesString = Console.ReadLine().Trim().ToLower(); | |
13 | ||
14 | Regex rg = new Regex(@"rotate\((\d+)\)"); | |
15 | ||
16 | int degrees = int.Parse(rg.Match(degreesString).Groups[1].ToString()); | |
17 | int rotationsCount = (degrees / 90) % 4; | |
18 | ||
19 | List<string> lines = new List<string>(); | |
20 | string input = Console.ReadLine(); | |
21 | ||
22 | while (input != "END") | |
23 | { | |
24 | lines.Add(input); | |
25 | input = Console.ReadLine(); | |
26 | } | |
27 | ||
28 | char[][] matrix = new char[lines.Count][]; | |
29 | int wordsLen = lines.Max(r => r.Length); | |
30 | ||
31 | for (int row = 0; row < lines.Count; row++) | |
32 | { | |
33 | matrix[row] = lines[row].PadRight(wordsLen).ToCharArray(); | |
34 | } | |
35 | ||
36 | for (int i = 0; i < rotationsCount; i++) | |
37 | { | |
38 | matrix = Rotate(matrix); | |
39 | } | |
40 | ||
41 | PrintMatrix(matrix); | |
42 | } | |
43 | ||
44 | private static void PrintMatrix(char[][] matrix) | |
45 | { | |
46 | foreach (var row in matrix) | |
47 | { | |
48 | Console.WriteLine(string.Join("", row)); | |
49 | } | |
50 | } | |
51 | ||
52 | private static char[][] Rotate(char[][] words) | |
53 | { | |
54 | char[][] result = new char[words.Max(w => w.Length)][]; | |
55 | ||
56 | for (int row = 0; row < result.Length; row++) | |
57 | { | |
58 | result[row] = new char[words.Length]; | |
59 | ||
60 | for (int col = 0; col < result[row].Length; col++) | |
61 | { | |
62 | result[row][col] = words[words.Length - 1 - col][row]; | |
63 | } | |
64 | } | |
65 | ||
66 | return result; | |
67 | } | |
68 | } | |
69 | } |