miroslavbstoyanov

Untitled

Jan 29th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 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. string readText = "";
  14. List<string> textList = new List<string>();
  15.  
  16. int maxLenght = 0;
  17. while ((readText = Console.ReadLine()) != "END")
  18. {
  19. int currentLegth = readText.Length;
  20. if (currentLegth > maxLenght)
  21. {
  22. maxLenght = currentLegth;
  23. }
  24. textList.Add(readText);
  25. }
  26.  
  27. char[][] matrix = new char[textList.Count][];
  28.  
  29. for (int row = 0; row < matrix.Length; row++)
  30. {
  31. matrix[row] = new char[maxLenght];
  32.  
  33. for (int coll = 0; coll < textList[row].Length; coll++)
  34. {
  35. matrix[row][coll] = textList[row][coll];
  36. }
  37. }
  38.  
  39. rotate %= 360;
  40.  
  41. switch (rotate)
  42. {
  43. case 0: PrintMatrix(matrix); break;
  44. case 90: PrintMatrix90(matrix, maxLenght); break;
  45. case 180: PrintMatrix180(matrix); break;
  46. case 270: PrintMatrix270(matrix, maxLenght); break;
  47. }
  48. }
  49.  
  50. private static void PrintMatrix90(char[][] matrix, int maxLenght)
  51. {
  52. for (int coll = 0; coll < maxLenght; coll++)
  53. {
  54. for (int row = matrix.Length - 1; row >= 0; row--) // 3
  55. {
  56. Console.Write("{0}", matrix[row][coll]);
  57. }
  58. Console.WriteLine();
  59. }
  60. }
  61.  
  62. private static void PrintMatrix270(char[][] matrix, int maxLenght)
  63. {
  64. for (int coll = maxLenght - 1; coll >= 0; coll--)
  65. {
  66. for (int row = 0; row < matrix.Length; row++)
  67. {
  68. Console.Write("{0}", matrix[row][coll]);
  69. }
  70. Console.WriteLine();
  71. }
  72. }
  73.  
  74. private static void PrintMatrix180(char[][] matrix)
  75. {
  76. for (int row = matrix.Length - 1; row >= 0; row--)
  77. {
  78. Console.WriteLine(string.Join("", matrix[row].Reverse()));
  79. }
  80. }
  81.  
  82. private static void PrintMatrix(char[][] matrix)
  83. {
  84. for (int row = 0; row < matrix.Length; row++)
  85. {
  86. Console.WriteLine(string.Join("", matrix[row]));
  87. }
  88. }
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment