Loading...

Във форума е въведено ограничение, което позволява на потребителите единствено да разглеждат публикуваните въпроси.

silvana1303 avatar silvana1303 5 Точки

02. Snake from C# Advanced Exam - 28 June 2020

Принтира ми се матрицата грешно и не разбирам защо, може ли помощ?

code:https://pastebin.com/RcTcQheU

You will be given an integer n for the size of the territory with square shape. On the next n lines, you will receive the rows of the territory. The snake will be placed on a random position, marked with the letter 'S'. There will also be food on random positions, marked with '*'. The territory may have lair. The lair will have two burrows marked with the letter - 'B'. All of the empty positions will be marked with '-'.

Each turn, you will be given command for the snake’s movement. When the snake moves it leaves a trail marked with '.'

Move commands will be: "up", "down", "left", "right".

If the snake moves to a food, it will eat the food, which will increase food quantity with one.

If it goes inside to a burrow, it goes out on the position of the other burrow and then both burrows disappear. If the snake goes out of its territory, the game is over. The snake needs at least 10 food quantity to be fed.

If the snake goes outside of its territory or has eaten enough food, the game should end.

Input

  • On the first line, you are given the integer n – the size of the square matrix.
  • The next n lines holds the values for every row.
  • On each of the next lines you will get a move command.

Output

  • On the first line:
    • If the snake goes out of its territory, print: "Game over!"
    • If the snake eat enough food, print: "You won! You fed the snake."
  • On the second line print all food eaten: "Food eaten: {food quantity}"
  • In the end print the matrix.

Constraints

  • The size of the square matrix will be between [2…10].
  • There will always be 0 or 2 burrows, marked with - 'B'.
  • The snake position will be marked with 'S'.
  • The snake will always either go out of its territory or eat enough food.
  • There will be no case in which the snake will go through itself.

 

 

Examples

Input

Output

Comments

6

-----S

----B-

------

------

--B---

--*---

left

down

down

down

left

Game over!

Food eaten: 1

----..

----.-

------

------

--.---

--.---

1) left     2) down     3) down     5) down

   ----S.      ----..      ----..      ----..

   ----B-      ----.-      ----.-      ----.-

   ------      ------      ------      ------

   ------      ------      ------      ------

   --B---      --S---      --.---      --.---

   --*---      --*---      --S---      --.---

3) eat the food: '*' (5, 2)

5) the snake goes out from its territory and the program ends

7

--***S-

--*----

--***--

---**--

---*---

---*---

---*---

left

left

left

down

down

right

right

down

left

down

You won! You fed the snake.

Food eaten: 10

--....-

--.----

--...--

---..--

---S---

---*---

---*---

 

 

Тагове:
0
C# Advanced 24/10/2020 00:10:49
georgi.d.gradev avatar georgi.d.gradev 50 Точки
Best Answer

Привет,

Намерих 3 грешки и след тяхната корекция кодът минава на 100/100 в Judge.

01. При валидацията в посока RIGHT вместо  if (snakeCol < 0) трябва да е if (snakeCol < n)

02. При търсенето на втората буква B (lair), във for цикъла вместо if (matrix[snakeRow, snakeCol] == 'B') трябва да е if (matrix[rows, cols] == 'B')

03. В условието, когато храната е станала 10, липсваше маркиране на настоящата позиция на змията преди break-а.

Console.WriteLine("You won! You fed the snake.");
matrix[snakeRow, snakeCol] = 'S';
 break;
 

Ето и редактираният код: https://pastebin.com/yJYRSV71 

1
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.