Advertisement
Prohause

String matrix rotation

Sep 23rd, 2018
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace debbuger_new
  7. {
  8. public class StartUp
  9. {
  10. public static void Main(string[] args)
  11. {
  12. var command = Console.ReadLine().Trim();
  13. var startIndex = command.IndexOf('(');
  14. var endIndex = command.IndexOf(')');
  15.  
  16. var degree = int.Parse(command.Substring(startIndex+1, endIndex-startIndex-1))%360;
  17. command = Console.ReadLine();
  18.  
  19. var allLines = new List<StringBuilder>();
  20.  
  21. while (!command.Equals("END"))
  22. {
  23. allLines.Add(new StringBuilder(command));
  24. command = Console.ReadLine();
  25. }
  26. var maxlenght = allLines.Select(p => p.Length).Max();
  27. switch (degree)
  28. {
  29. case 0:allLines.ForEach(Console.WriteLine);break;
  30. case 90:
  31. for (var i = 0; i < maxlenght; i++)
  32. {
  33. for (var j = allLines.Count-1; j >=0; j--)
  34. {
  35. try
  36. {
  37. Console.Write(allLines[j][i]);
  38. }
  39. catch (Exception)
  40. {
  41. Console.Write(" ");
  42. }
  43. }
  44. Console.WriteLine();
  45. }
  46. break;
  47. case 180:
  48.  
  49. for (var i = allLines.Count-1; i >=0; i--)
  50. {
  51. Console.WriteLine(new string(' ',maxlenght-allLines[i].Length) +string.Join("",allLines[i].ToString().Reverse()));
  52. }
  53. break;
  54. case 270:
  55. for (var i = maxlenght-1; i >= 0; i--)
  56. {
  57. foreach (var t in allLines)
  58. {
  59. try
  60. {
  61. Console.Write(t[i]);
  62. }
  63. catch (Exception)
  64. {
  65. Console.Write(" ");
  66. }
  67. }
  68. Console.WriteLine();
  69. }
  70. break;
  71. }
  72.  
  73. }
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement