Advertisement
Guest User

Untitled

a guest
Jun 6th, 2017
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace StringMatrixRotation
  8. {
  9. class StartUp
  10. {
  11. static void Main()
  12. {
  13. string[] rotation = Console.ReadLine().Split(new char[] { '(' , ')'},
  14. StringSplitOptions.RemoveEmptyEntries).ToArray();
  15.  
  16. int rotateDegree = int.Parse(rotation[1]);
  17.  
  18. List<string> words = new List<string>();
  19.  
  20. while (true)
  21. {
  22. string input = Console.ReadLine();
  23. if (input == "END") break;
  24.  
  25. words.Add(input);
  26. }
  27.  
  28. int maxLength = words.Max(v => v.Length);
  29.  
  30. char[][] jaggedArray = new char[words.Count][];
  31.  
  32. FillMatrix(words, maxLength, jaggedArray);
  33.  
  34. RotateMatrix(ref jaggedArray, maxLength, rotateDegree);
  35.  
  36. PrintMatrix(jaggedArray);
  37.  
  38. }
  39.  
  40. private static void PrintMatrix(char[][] jaggedArray)
  41. {
  42. foreach (var array in jaggedArray)
  43. {
  44. Console.WriteLine(string.Join("", array));
  45. }
  46. }
  47.  
  48. private static void RotateMatrix(ref char[][] jaggedArray,int maxLength, int rotateDegree)
  49. {
  50. int rotation = rotateDegree / 90;
  51.  
  52. for (int i = 0; i < rotation; i++)
  53. {
  54. if (i % 2 == 0)
  55. {
  56. int index = 0;
  57.  
  58. char[][] tempArray = new char[maxLength][];
  59.  
  60. for (int k = 0, x = 0; k < maxLength; k++, x++)
  61. {
  62. tempArray[x] = new char[jaggedArray.Length];
  63.  
  64. for (int j = 0, z = jaggedArray.Length - 1; j < jaggedArray.Length; j++, z--)
  65. {
  66. tempArray[x][j] = jaggedArray[z][index];
  67. }
  68. index++;
  69. }
  70. jaggedArray = tempArray;
  71. }
  72. else
  73. {
  74. char[][] tempArray = new char[jaggedArray[0].Length][];
  75. int index = 0;
  76.  
  77. for (int k = 0; k < jaggedArray[0].Length; k++)
  78. {
  79. tempArray[k] = new char[maxLength];
  80.  
  81. for (int l = jaggedArray.Length- 1, z = 0 ; l >= 0; l--, z++)
  82. {
  83. tempArray[k][z] = jaggedArray[l][index];
  84. }
  85. index++;
  86. }
  87. jaggedArray = tempArray;
  88. }
  89. }
  90. }
  91.  
  92. private static void FillMatrix(List<string> words, int maxLength, char[][] jaggedArray)
  93. {
  94. for (int i = 0; i < jaggedArray.Length; i++)
  95. {
  96. jaggedArray[i] = new char[maxLength];
  97.  
  98. char[] wordInChars = words[i].ToCharArray();
  99.  
  100. for (int k = 0; k < jaggedArray[i].Length; k++)
  101. {
  102. if (wordInChars.Length > k)
  103. {
  104. jaggedArray[i][k] = wordInChars[k];
  105. }
  106. else
  107. {
  108. jaggedArray[i][k] = ' ';
  109. }
  110. }
  111. }
  112. }
  113. }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement