Професионална програма
+ Нов въпрос
SamPav avatar SamPav 2 Точки

Помощ за задача - Moving Target


ако някой може да помогне със задачата, стигам до 80/100 и не мога да разбера къде греша, някое гранично условие ли, друго ли,

ето го кода ми https://pastebin.com/DW2bMYCX

ето го условието на задачата:

Moving Target

You are at the shooting gallery again and you need a program that helps you keep track of moving targets. On the first line, you will receive a sequence of targets with their integer values, split by a single space. Then, you will start receiving commands for manipulating the targets, until the "End" command. The commands are the following:

  • Shoot {index} {power}
    • Shoot the target at the index, if it exists by reducing its value by the given power (integer value).A target is considered shot when its value reaches 0.
    • Remove the target, if it is shot.
  • Add {index} {value}
    • Insert a target with the received value at the received index, if it exist. If not, print: "Invalid placement!"
  • Strike {index} {radius}
    • Remove the target at the given index and the ones before and after it depending on the radius, if such exist. If any of the indices in the range is invalid print:

"Strike missed!" and skip this command.

 Example:  Strike 2 2


  • strikeIndex}




  • End
    • Print the sequence with targets in the following format:

Input / Constraints

  • On the first line you will receive the sequence of targets integer values [1-10000].
  • On the next lines, until the "End" will be receiving the command described above – strings.
  • There will never be a case when "Strike" command would empty the whole sequence.


  • Print the appropriate message in case of "Strike" command if necessary.
  • In the end, print the sequence of targets in the format described above.





52 74 23 44 96 110

Shoot 5 10

Shoot 1 80

Strike 2 1

Add 22 3


Invalid placement!


The first command is "Shoot", so we reduce the target on index 5, which is valid, with the given power10.

Then we receive the same command but we need to reduce the target on the 1st index, with power 80. The value of this target is 74, so it is considered shot and we remove it.

Then we receive the "Strike" command on the 2nd index and we need to check if the range with radius 1 is valid:

52 23 44 96 100

And it is, so we remove the targets.

At last we receive the "Add" command, but the index is invalid so we print the appropriate message and in the end we have the following result:


47 55 85 78 99 20

Shoot 1 55

Shoot 8 15

Strike 2 3

Add 0 22

Add 2 40

Add 2 50


Strike missed!




Благодаря предварително!

JavaScript Fundamentals
SamPav avatar SamPav 2 Точки

Сам си открих грешката, 100/100 :)

условието в задачата е: 

  • There will never be a case when "Strike" command would empty the whole sequence.

смених if -a :

if ((i - radius !== -1 && i - radius !== undefined) && (radius+i !== -1 && radius+i !== undefined))


if (i - radius >= 0 && radius+i <= targets.length)


30/06/2020 11:26:39