Sim0o0na

Untitled

Jan 29th, 2017
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 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 TrophonTheGrumpyCat
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int matrixRowsCount = int.Parse(Console.ReadLine());
  14. List<string> matrix = new List<string>();
  15. int currentCol = 0;
  16. int currentRow = 0;
  17. for (int i = 0; i < matrixRowsCount; i++)
  18. {
  19. matrix.Add(Console.ReadLine());
  20. if (matrix[i].Contains("S"))
  21. {
  22. currentRow = i;
  23. currentCol = matrix[i].IndexOf("S");
  24. }
  25. }
  26.  
  27. string directions = Console.ReadLine();
  28. int turns = 0;
  29. for (int i = 0; i < directions.Length; i++)
  30. {
  31. turns++;
  32. char move = directions[i];
  33. switch (move)
  34. {
  35. case 'D':
  36. while (true)
  37. {
  38. currentRow++;
  39.  
  40. if (currentRow == matrix.Count())
  41. {
  42. currentRow = 0;
  43. if (currentCol >= matrix[currentRow].Length)
  44. {
  45. continue;
  46. }
  47. else
  48. {
  49. break;
  50. }
  51. }
  52. if (currentCol >= matrix[currentRow].Length)
  53. {
  54. continue;
  55. }
  56. else
  57. {
  58. break;
  59. }
  60. }
  61. break;
  62. case 'U':
  63. while (true)
  64. {
  65. currentRow--;
  66. if (currentRow == -1)
  67. {
  68. currentRow = matrix.Count() - 1;
  69. if (currentCol >= matrix[currentRow].Length)
  70. {
  71. continue;
  72. }
  73. else
  74. {
  75. break;
  76. }
  77. }
  78. if (currentCol >= matrix[currentRow].Length)
  79. {
  80. continue;
  81. }
  82. else
  83. {
  84. break;
  85. }
  86. }
  87. break;
  88. case 'L':
  89. currentCol--;
  90. if (currentCol == -1)
  91. {
  92. currentCol = matrix[currentRow].Length - 1;
  93. }
  94. break;
  95. case 'R':
  96. currentCol++;
  97. if (currentCol== matrix[currentRow].Length)
  98. {
  99. currentCol = 0;
  100. }
  101. break;
  102. }
  103. if (matrix[currentRow][currentCol] == 'E')
  104. {
  105. Console.WriteLine("Experiment successful. {0} turns required.", turns);
  106. return;
  107. }
  108. }
  109. Console.WriteLine("Robot stuck at {0} {1}. Experiment failed.", currentRow, currentCol);
  110. }
  111. }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment