Loading...

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

plamena.vylcheva avatar plamena.vylcheva 0 Точки

Moving Target - Runtime error

Здравейте!

Имам проблем с тази задача, като последните два теста в judge ми гърмят с runtime error, не мога да си окрия грешката.

Ще се радвам, ако някой хвърли един поглед, какво точно не съм спазила като условие.

 Моят код: http://pastebin.com/yydANXEQ 

http://judge.softuni.org/Contests/Practice/Index/2305#2

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).
    • Remove the target if it is shot. A target is considered shot when its value reaches 0.
  • "Add {index} {value}"
    • Insert a target with the received value at the received index if it exists.
    • 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 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 and end the program:
      •  

Input / Constraints

 

 

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

Output

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

Examples

Input

Output

Comments

52 74 23 44 96 110

Shoot 5 10

Shoot 1 80

Strike 2 1

Add 22 3

End

1 2 3 4 5

Strike 2 2

End

Invalid placement!

52|100

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:

52|100

1 2 3 4 5

Strike 0 1

End

Strike missed!

1|2|3|4|5

 

JS Examples

Input

Output

Comments

(["52 74 23 44 96 110",

"Shoot 5 10",

"Shoot 1 80",

"Strike 2 1",

"Add 22 3",

"End"])

Invalid placement!

52|100

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:

52|100

(["1 2 3 4 5",

"Strike 0 1",

"End"])

Strike missed!

1|2|3|4|5

 

 

Тагове:
0
Fundamentals Module
icowwww avatar icowwww 2673 Точки

Здравей,

Имаш 2 грешки:

1. На ред 22 трябва да проверяваш дали индексите са валидни, но проверяваш shootPower

if (shootPower >= 0 && shootIndex < targets.size()) =>  f (shootIndex >= 0 && shootIndex < targets.size())

2. На ред 50 махаш елементи с 

targets.removeAll(targets.subList(strikeIndex - radius, strikeIndex + radius + 1));

, което ще даде view на масива от/до определен индекс и след това ще изтрие всички намерени поредици. 

Например ако имаш лист

0 1 2 3 4 0 1 2 3 4

и команда: Strike 2 2

Кода ти ще открие, че трябва да изтрие поредицата 0 1 2 3 4, която съществува два пъти. Това ще направи лист-а празен, защото такава поредица съществува 2 пъти.

Можеш да използваш clear за минимални промени.

 

Решението с коментари:

https://pastebin.com/FcbGTcjA

1
15/06/2023 00:20:27
plamena.vylcheva avatar plamena.vylcheva 0 Точки

Много Ви благодаря! :)

0
Panvarvis avatar Panvarvis 0 Точки

Никога не съм опитвал да стартирам тази програма. Но вашите коментари си струва да научите повече за тях. Знанието винаги се актуализира и се открива повече. Това е наистина чудесно за по-дълго запаметяване snake io

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