Професионална програма
Loading...
+ Нов въпрос
Valentin.Shumankov avatar Valentin.Shumankov 5 Точки

9. Miner Решение

https://pastebin.com/SyBU45iz

Дано е полезно на някого да разбере  по добре задачата .

*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
5
up right right up right
* * * c *
* * * e *
* * c * *
s * * c *
* * c * *
Game over! (1, 3)
4
up right right right down
* * * e
* * c *
* s * c
* * * *
You collected all coals! (2, 3)
6
left left down right up left left down down down
* * * * * *
e * * * c *
* * c s * *
* * * * * *
c * * * c *
* * c * * *
coals left. (5, 0)
 

 

Тагове:
0
C# Advanced 26/01/2021 22:54:11
kurio avatar kurio 1 Точки

Абе на тва ли ви учат в тоя ПУЦ,(Как да решим елементарна задача по възможно най-сложния начин?)

Голямо решение ,може да се загуби човек в него! Наблъскал си 100 for цикъла и излишни проверки и нови обекти (както се вика спагети код) Вас C-ШАХТАДЖИИТЕ много ви е страх да пишете функции , камо ли отделен клас извън Main.

Разцъках ви бая от  примерчетата за "Advanced" (по -скоро "elementary") и най-трудните от тях се решават  за 30 - 40 мин.

Пробвай да решаваш задачки от "Facebook Hack Cup" там със C - ШАХТА(c#), Java ,че дори и с Python зорлем щe докопаш до първите 40 - 50. Най-добрите пишат на C/C++ или RUST (все "остарели" езици където учим ние дебилите от ТУ София)

Еи ти 3 -4  пъти по-елементарно решение на твоята задача, и доста по разбираемо написано на Python от мен.

https://pastebin.com/XZ5QVw5a

 

P.S. Поздрави от Тъпаците от ТУ София

0
20/02/2021 11:15:23