Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.44 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. bool coordinatesExist = row >= 0 && row <= jaggerArray.Length - 1 && col >= 0 && col <= jaggerArray[row].Length - 1;
  39. if (toDo == "Collect")
  40. {
  41. if (coordinatesExist)
  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 (coordinatesExist)
  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 (coordinatesExist)
  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 (coordinatesExist)
  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 (coordinatesExist)
  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 (coordinatesExist)
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement