Loading...

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

StanimirSergev99 avatar StanimirSergev99 0 Точки

02. Treasure Hunt - Java Advanced Retake Exam - 18 August 2022

Здравейте на тази задача ми гърми тест номер 4 (Runtime error). Какво ли не пробвах и не гърми. Единствения начин по който се сетих в който ще гръмне е ако се въведе String в началото а не числа. Но това ми се струва абсурдно. Моля ако някой може да погледне кода: 
https://pastebin.com/Zsjvbu5i 

Условиета на задачата (Матрица)

You will be given N and M – integers, indicating the field's dimensions, shown on the secret map. On the next N lines, you will receive the rows of the field. You will be placed in a random position, marked with the letter 'Y'. On random positions, there will be trees marked with the letter 'T'. The treasure is marked with the letter 'X'. All of the empty positions will be marked with '-'.
You will receive a few lines with commands representing which direction you need to move. The possible directions are up, down, right, and left.
If you go out of the field, you need to stay in the last possible position inside the field.
If you step on a tree (position marked with 'T'), go one step back to the direction you came from (not make a move).
If the given command is "Finish" you need to check the position you are standing on. If it is marked with 'X' this means you have found the treasure, and you have to print the following message: "I've found the treasure!". Then print the correct directions you went to in order to find the treasure.
Otherwise, print: "The map is fake!".
Input
⦁    On the first line, you'll receive the field dimensions in the format: "N M", where N is the number of rows, and M is the number of columns. They'll be separated by a single space (" ").
⦁    On the next N lines, you will receive a string representing the respective row of the field. The positions in every string will be separated by a single space (" ").
⦁    On the next few lines, until you receive the command "Finish", you will be given directions (up, down, right, left). 

Output
⦁    There are two types of output:
⦁    If you have found the treasure (the last step is on a position marked with 'X') print the following output: "I've found the treasure!".
On the next line, print the correct directions you went to find the treasure (do not include the directions that made you go out of the field or step on a tree). The directions must be separated by a comma and space (", "). It should look like this:
"The right path is {direction1}, {direction2}, …".
⦁    If you have not found the treasure, print the following message: "The map is fake!".

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 'X' and only one 'Y'.
⦁    If the steps are invalid, do not include them in the result.

Input 1 
5 8
- - - T - - - T
- X - T T - - -
- - - - - - T -
- - Y - T - - T
- - - T - - - -
up
up
left
Finish

Output 1 

I've found the treasure!
The right path is up, up, left

==========================

Input 2

4 7
T - - T - T T
- - - - - X -
T - - - - - -
Y - - - - - T
left
right
right
up
Finish

Output 2

The map is fake!

Тагове:
0
Module: Java Advanced
MartinBG avatar MartinBG 4803 Точки

Тест №4 има невалиден според условието на задачата вход: някой от редовете на полето е с по-малко елементи, от M (колоните на матрицата).

За заобикаляне на проблема:

        for (int row = 0; row < matrixRow; row++) {
            String[] input = scan.nextLine().split("\\s+");
            for (int col = 0; col < matrixCol; col++) {
            //    matrix[row][col] = input[col];
                if (col < input.length) {
                    matrix[row][col] = input[col];
                } else {
                    matrix[row][col] = "-";
                }
            }
        }  // Matrix Input

 

1
08/02/2023 02:41:40
tripTiPscout avatar tripTiPscout 24 Точки

@MartinBG

Здравейте, бихте ли ми съдействали по този проект: https://gitlab.edu.reachup.bg/peter_sto/maproutefinder

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

Програмката търси най-оптимален път между два града А* алгоритъм. Към момента само по координати на градовете latitude и longitude.

Искам да добавя и пътища с дължина, максимална скорост и от каде до каде е.

Двата основни класа са Town и Road.

Някой с малко насоки как да подходя без да добавям логика в основните класове, а само в service-те?

peter_sto@mail.bg

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