Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.31 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace SeashellTreasure
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. int n = int.Parse(Console.ReadLine());
  12. string[][] jaggerArray = new string[n][];
  13. int collectedShellsCount = 0;
  14. int stolenShellsCount = 0;
  15. List<string> collectedShells = new List<string>();
  16.  
  17. for (int i = 0; i < n; i++)
  18. {
  19. string[] line = Console.ReadLine()
  20. .Split(" ", StringSplitOptions.RemoveEmptyEntries)
  21. .ToArray();
  22. jaggerArray[i] = new string[line.Length];
  23.  
  24. for (int j = 0; j < line.Length; j++)
  25. {
  26. jaggerArray[i][j] = line[j];
  27. }
  28. }
  29.  
  30. string command = Console.ReadLine();
  31.  
  32. while (command != "Sunset")
  33. {
  34. string[] commandInfo = command.Split();
  35. string toDo = commandInfo[0];
  36. int row = int.Parse(commandInfo[1]);
  37. int col = int.Parse(commandInfo[2]);
  38. IsInRange(row, col, jaggerArray);
  39. if (toDo == "Collect")
  40. {
  41. if (IsInRange(row, col, jaggerArray))
  42. {
  43. if (jaggerArray[row][col] != "-")
  44. {
  45. collectedShells.Add(jaggerArray[row][col]);
  46. collectedShellsCount++;
  47. jaggerArray[row][col] = "-";
  48. }
  49. }
  50. }
  51. else if (toDo == "Steal")
  52. {
  53. string direction = commandInfo[3];
  54. if (IsInRange(row, col, jaggerArray))
  55. {
  56. if (jaggerArray[row][col] != "-")
  57. {
  58. stolenShellsCount++;
  59. jaggerArray[row][col] = "-";
  60. }
  61. switch (direction)
  62. {
  63. case "up":
  64. for (int i = 0; i < 3; i++)
  65. {
  66. row--;
  67. if (IsInRange(row, col, jaggerArray))
  68. {
  69. if (jaggerArray[row][col] != "-")
  70. {
  71. stolenShellsCount++;
  72. jaggerArray[row][col] = "-";
  73. }
  74. }
  75. }
  76. break;
  77. case "down":
  78. for (int i = 0; i < 3; i++)
  79. {
  80. row++;
  81. if (IsInRange(row, col, jaggerArray))
  82. {
  83. if (jaggerArray[row][col] != "-")
  84. {
  85. stolenShellsCount++;
  86. jaggerArray[row][col] = "-";
  87. }
  88. }
  89. }
  90. break;
  91. case "left":
  92. for (int i = 0; i < 3; i++)
  93. {
  94. col--;
  95. if (IsInRange(row, col, jaggerArray))
  96. {
  97. if (jaggerArray[row][col] != "-")
  98. {
  99. stolenShellsCount++;
  100. jaggerArray[row][col] = "-";
  101. }
  102. }
  103. }
  104. break;
  105. case "right":
  106. for (int i = 0; i < 3; i++)
  107. {
  108. col++;
  109. if (IsInRange(row, col, jaggerArray))
  110. {
  111. if (jaggerArray[row][col] != "-")
  112. {
  113. stolenShellsCount++;
  114. jaggerArray[row][col] = "-";
  115. }
  116. }
  117. }
  118. break;
  119. }
  120.  
  121. }
  122. }
  123.  
  124. command = Console.ReadLine();
  125. }
  126.  
  127.  
  128. //foreach (string[] element in jaggerArray)
  129. //{
  130. // Console.WriteLine(string.Join(" ", element));
  131. //}
  132. //Console.Write($"Collected seashells: {collectedShellsCount} -> ");
  133. //Console.WriteLine(string.Join(", ", collectedShells));
  134. //Console.WriteLine($"Stolen seashells: {stolenShellsCount}");
  135.  
  136.  
  137. for (int row = 0; row < jaggerArray.Length; row++)
  138. {
  139. for (int col = 0; col < jaggerArray[row].Length; col++)
  140. {
  141. Console.Write(jaggerArray[row][col] + " ");
  142. }
  143. Console.WriteLine();
  144. }
  145. Console.Write($"Collected seashells: {collectedShellsCount}");
  146.  
  147. if (collectedShells.Count > 0)
  148. {
  149. Console.Write($" -> {string.Join(", ", collectedShells)}");
  150. }
  151. Console.WriteLine();
  152.  
  153.  
  154. Console.WriteLine($"Stolen seashells: {stolenShellsCount}");
  155. }
  156.  
  157. private static bool IsInRange(int row, int col, string[][] jaggerArray)
  158. {
  159. return row >= 0 && row < jaggerArray.Length && col >= 0 && col < jaggerArray[row].Length;
  160. }
  161. }
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement