miroslavbstoyanov

Untitled

Jan 29th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _12._String_Matrix_Rotation
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. string[] command = Console.ReadLine().Split(new string[] { "(", ")", " " }, StringSplitOptions.RemoveEmptyEntries);
  12. int rotate = int.Parse(command[1]);
  13.  
  14. char[][] matrix = GetMatrix();
  15.  
  16. rotate %= 360;
  17.  
  18. switch (rotate)
  19. {
  20. case 0: PrintMatrix(matrix); break;
  21. case 90: PrintMatrix90(matrix); break;
  22. case 180: PrintMatrix180(matrix); break;
  23. case 270: PrintMatrix270(matrix); break;
  24. }
  25. }
  26.  
  27. private static char[][] GetMatrix()
  28. {
  29. string readText = "";
  30. List<string> textList = new List<string>();
  31.  
  32. int maxLenght = 0;
  33. while ((readText = Console.ReadLine()) != "END")
  34. {
  35. int currentLegth = readText.Length;
  36. if (currentLegth > maxLenght)
  37. {
  38. maxLenght = currentLegth;
  39. }
  40. textList.Add(readText);
  41. }
  42.  
  43. char[][] matrix = new char[textList.Count][];
  44.  
  45. for (int row = 0; row < matrix.Length; row++)
  46. {
  47. matrix[row] = new char[maxLenght];
  48.  
  49. for (int coll = 0; coll < matrix[row].Length; coll++)
  50. {
  51. if (textList[row].Length > coll)
  52. {
  53. matrix[row][coll] = textList[row][coll];
  54. }
  55. else
  56. {
  57. matrix[row][coll] = ' ';
  58. }
  59. }
  60. }
  61. return matrix;
  62. }
  63.  
  64. private static void PrintMatrix90(char[][] matrix)
  65. {
  66. for (int coll = 0; coll < matrix[0].Length; coll++)
  67. {
  68. for (int row = matrix.Length - 1; row >= 0; row--)
  69. {
  70. Console.Write("{0}", matrix[row][coll]);
  71. }
  72. Console.WriteLine();
  73. }
  74. }
  75.  
  76. private static void PrintMatrix270(char[][] matrix)
  77. {
  78. for (int coll = matrix[0].Length - 1; coll >= 0; coll--)
  79. {
  80. for (int row = 0; row < matrix.Length; row++)
  81. {
  82. Console.Write("{0}", matrix[row][coll]);
  83. }
  84. Console.WriteLine();
  85. }
  86. }
  87.  
  88. private static void PrintMatrix180(char[][] matrix)
  89. {
  90. for (int row = matrix.Length - 1; row >= 0; row--)
  91. {
  92. Console.WriteLine(string.Join("", matrix[row].Reverse()));
  93. }
  94. }
  95.  
  96. private static void PrintMatrix(char[][] matrix)
  97. {
  98. for (int row = 0; row < matrix.Length; row++)
  99. {
  100. Console.WriteLine(string.Join("", matrix[row]));
  101. }
  102. }
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment