Advertisement
Guest User

Untitled

a guest
May 19th, 2015
563
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 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 StringMatrixRotationProblem2
  8. {
  9. class StringMatrixRotation
  10. {
  11.  
  12. static void Main()
  13. {
  14. string command = Console.ReadLine();
  15. int first = command.IndexOf("(");
  16. int last = command.IndexOf(")");
  17. int lenght = last - first;
  18. string number = command.Substring(first + 1, lenght - 1);
  19. int degrees = int.Parse(number);
  20. List<string> l = new List<string>();
  21. int maxLength = 0;
  22. int rows = 0;
  23. string input = Console.ReadLine();
  24. while (input != "END")
  25. {
  26. rows++;
  27. l.Add(input);
  28. if (input.Length > maxLength)
  29. {
  30. maxLength = input.Length;
  31. }
  32. input = Console.ReadLine();
  33. }
  34. char[,] matrix = new char[rows, maxLength];
  35. int index = 0;
  36. int item = 0;
  37.  
  38. for (int row = 0; row < matrix.GetLength(0); row++)
  39. {
  40. string word = l[item];
  41. int itemLength = word.Length;
  42. for (int col = 0; col < matrix.GetLength(1); col++)
  43. {
  44. if (index == itemLength)
  45. {
  46. while (index < maxLength)
  47. {
  48. matrix[row, col] = ' ';
  49. index++;
  50. col++;
  51. }
  52. index = 0;
  53. break;
  54. }
  55. else
  56. {
  57. matrix[row, col] = word[index];
  58. index++;
  59. }
  60. }
  61. item++;
  62. index = 0;
  63.  
  64.  
  65. }
  66. Rotate(matrix, degrees);
  67. }
  68. static void Rotate(char[,] m, int degrees)
  69. {
  70. switch(degrees)
  71. {
  72. case 90:
  73.  
  74. for (int col = 0; col < m.GetLength(1); col++)
  75. {
  76. for (int row = m.GetLength(0) - 1; row >= 0; row--)
  77. {
  78. Console.Write(m[row, col]);
  79. }
  80. Console.WriteLine();
  81. }
  82. break;
  83. case 180:
  84. for (int r = m.GetLength(0) - 1; r >= 0; r--)
  85. {
  86. for (int c = m.GetLength(1) - 1; c >= 0; c--)
  87. {
  88. Console.Write(m[r, c]);
  89. }
  90. Console.WriteLine();
  91. }
  92. break;
  93. case 270:
  94. for (int col = m.GetLength(1) - 1; col >= 0; col--)
  95. {
  96. for (int row = 0; row <= m.GetLength(0) - 1; row++)
  97. {
  98. Console.Write(m[row, col]);
  99. }
  100. Console.WriteLine();
  101. }
  102. break;
  103. case 360:
  104. for (int row = 0; row < m.GetLongLength(0); row++)
  105. {
  106. for (int col = 0; col < m.GetLongLength(1); col++)
  107. {
  108. Console.Write(m[row, col]);
  109. }
  110. Console.WriteLine();
  111. }
  112. break;
  113. }
  114.  
  115. }
  116. }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement