Loading...

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

AnzhelaNurieva avatar AnzhelaNurieva 4 Точки

Problem 9 *Miner

Здравейте, имам нужда от малко помощ Judge и дава 70/100, не отркривам възможна грешка.

решение => https://pastebin.com/ZQ7sgssX

условие =>

 9 *Miner 

We get as input the size of the field in which our miner moves. The field is always a square. After that we will receive the commands which represent the directions in which the miner should move. The miner starts from position – ‘s’. The commands will be: left, right, up and down. If the miner has reached a side edge of the field and the next command indicates that he has to get out of the field, he must remain on his current possition and ignore the current command. The possible characters that may appear on the screen are: 

  • * – a regular position on the field. 

  • e – the end of the route.  

  • c  - coal 

  • s - the place where the miner starts 

Each time when the miner finds a coal, he collects it and replaces it with '*'. Keep track of the count of the collected coals. If the miner collects all of the coals in the field, the program stops and you have to print the following message: "You collected all coals! ({rowIndex}, {colIndex})". 

If the miner steps at 'e' the game is over (the program stops) and you have to print the following message: "Game over! ({rowIndex}, {colIndex})". 

If there are no more commands and none of the above cases had happened, you have to print the following message: "{remainingCoals} coals left. ({rowIndex}, {colIndex})". 

Input 

  • Field size – an integer number. 

  • Commands to move the miner – an array of strings separated by " ". 

  • The field: some of the following characters (*, e, c, s), separated by whitespace (" "); 

Output 

  • There are three types of output: 

  • If all the coals have been collected, print the following output: "You collected all coals! ({rowIndex}, {colIndex})" 

  • If you have reached the end, you have to stop moving and print the following line: "Game over! ({rowIndex}, {colIndex})" 

  • If there are no more commands and none of the above cases had happened, you have to print the following message: "{totalCoals} coals left. ({rowIndex}, {colIndex})" 

Constraints 

  • The field size will be a 32-bit integer in the range [0 … 2 147 483 647]. 

  • The field will always have only one’s’. 

  • Allowed working time for your program: 0.1 seconds. 

  • Allowed memory: 16 MB. 

Examples 

Input 

Output 

up right right up right 

* * * c * 

* * * e * 

* * c * * 

s * * c * 

* * c * * 

Game over! (1, 3) 

 

Стъпихме на (е) играта приключи! 

up right right right down 

* * * e 

* * c * 

* s * c 

* * * * 

You collected all coals! (2, 3) 

left left down right up left left down down down 

* * * * * * 

e * * * c * 

* * c s * * 

* * * * * * 

c * * * c * 

* * c * * * 

  1. coals left. (5, 0) 

0
C# Advanced 03/01/2021 16:34:38
Elena123456 avatar Elena123456 235 Точки

Здравейте, наскоро отделих няколко дена специално за тази задача и никак не съжалявам. Мисля, че тази тема би Ви била от голяма полза не само за въпросната задача, но като цяло за подобряване качеството на кода, защото и това е дискутирано-  https://softuni.bg/forum/30887/problem-sys-zadacha-9-miner

Ако след разглеждането й не успеете да си откриете грешката, моля пишете отново.

Успех!

 

0
MartinBG avatar MartinBG 4803 Точки

Проблемът е, че IsInRange променливата се сетва еднократно на false извън основния цикъл (ред №23), вместо това да се прави за всяка команда.

Премaхнете този ред (№23):

bool IsInRange = false;

И го добавете в началото на foreach цикъла:

            foreach (var command in commands)
            {
                bool IsInRange = false;

 

Между другото, по конвенция променливите трябва да започват с малка буква, т.е. isInRange вместо IsInRange.

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