Advertisement
Iv555

Untitled

Feb 18th, 2022
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.75 KB | None | 0 0
  1. using System;
  2.  
  3. namespace T02Armory
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9.  
  10. int sizes = int.Parse(Console.ReadLine());
  11. char[,] armoryMatrix = new char[sizes, sizes];
  12. int armoryOfficerRow = 0;
  13. int armoryOfficerCol = 0;
  14.  
  15. int firstMirrorRow = 0;
  16. int firstMirrorCol = 0;
  17. int secondMirrorRow = 0;
  18. int secondMirrorCol = 0;
  19. int countMirrors = 0;
  20.  
  21. for (int i = 0; i < armoryMatrix.GetLength(0); i++)
  22. {
  23. char[] currRow = Console.ReadLine().ToCharArray();
  24. for (int j = 0; j < armoryMatrix.GetLength(1); j++)
  25. {
  26. armoryMatrix[i, j] = currRow[j];
  27. if (armoryMatrix[i, j] == 'A')
  28. {
  29. armoryOfficerRow = i;
  30. armoryOfficerCol = j;
  31. }
  32.  
  33. if (armoryMatrix[i, j] == 'M')
  34. {
  35. if (countMirrors == 0)
  36. {
  37. firstMirrorRow = i;
  38. firstMirrorCol = j;
  39. countMirrors++;
  40. }
  41. else
  42. {
  43. secondMirrorRow = i;
  44. secondMirrorCol = j;
  45. }
  46. }
  47. }
  48. }
  49.  
  50. int boughtSwardsAmount = 0;
  51.  
  52. while (IsWithinMatrix(armoryMatrix, armoryOfficerRow, armoryOfficerCol) && boughtSwardsAmount <= 65)
  53. {
  54. string direction = Console.ReadLine();
  55. armoryMatrix[armoryOfficerRow, armoryOfficerCol] = '-';
  56.  
  57. switch (direction)
  58. {
  59. case "left":
  60. armoryOfficerCol -= 1;
  61. break;
  62. case "right":
  63. armoryOfficerCol += 1;
  64. break;
  65. case "up":
  66. armoryOfficerRow -= 1;
  67. break;
  68. case "down":
  69. armoryOfficerRow += 1;
  70. break;
  71. }
  72.  
  73. if (IsWithinMatrix(armoryMatrix, armoryOfficerRow, armoryOfficerCol) &&
  74. Char.IsDigit(armoryMatrix[armoryOfficerRow, armoryOfficerCol]))
  75. {
  76. boughtSwardsAmount += int.Parse(armoryMatrix[armoryOfficerRow, armoryOfficerCol].ToString());
  77. armoryMatrix[armoryOfficerRow, armoryOfficerCol] = 'A';
  78. }
  79. else if (IsWithinMatrix(armoryMatrix, armoryOfficerRow, armoryOfficerCol) &&
  80. armoryMatrix[armoryOfficerRow, armoryOfficerCol] == 'M')
  81. {
  82. if (armoryOfficerRow == firstMirrorRow && armoryOfficerCol == firstMirrorCol)
  83. {
  84. armoryMatrix[armoryOfficerRow, armoryOfficerCol] = '-';
  85. armoryOfficerRow = secondMirrorRow;
  86. armoryOfficerCol = secondMirrorCol;
  87.  
  88. }
  89. else if (armoryOfficerRow == secondMirrorRow && armoryOfficerCol == secondMirrorCol)
  90. {
  91. armoryMatrix[armoryOfficerRow, armoryOfficerCol] = '-';
  92. armoryOfficerRow = firstMirrorRow;
  93. armoryOfficerCol = firstMirrorCol;
  94. }
  95. armoryMatrix[armoryOfficerRow, armoryOfficerCol] = 'A';
  96. }
  97.  
  98. }
  99.  
  100. if (!IsWithinMatrix(armoryMatrix, armoryOfficerRow, armoryOfficerCol))
  101. {
  102. Console.WriteLine("I do not need more swords!");
  103. }
  104.  
  105. else if (boughtSwardsAmount > 65)
  106. {
  107. Console.WriteLine("Very nice swords, I will come back for more!");
  108. }
  109.  
  110. Console.WriteLine($"The king paid {boughtSwardsAmount} gold coins.");
  111. Printmatrix(armoryMatrix);
  112. }
  113.  
  114. public static bool IsWithinMatrix(char[,] matrix, int row, int col)
  115. => row >= 0 && row < matrix.GetLength(0) && col >= 0 && col < matrix.GetLength(1);
  116.  
  117. public static void Printmatrix(char[,] matrix)
  118. {
  119. for (int i = 0; i < matrix.GetLength(0); i++)
  120. {
  121. for (int j = 0; j < matrix.GetLength(1); j++)
  122. {
  123. Console.Write(matrix[i, j]);
  124. }
  125.  
  126. Console.WriteLine();
  127. }
  128.  
  129. }
  130. }
  131. }
  132.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement