Loading...

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

MariqnK1 avatar MariqnK1 52 Точки

Shoot for the Win 0/100

Не мога да разбера как да работя пряко с индексите. Може ли малко пояснение?

 

Условие:

https://judge.softuni.bg/Contests/Practice/Index/2305#1

Write a program that helps you keep track of your shot targets. You will receive a sequence with integers, separated by single space, representing targets and their value. Afterwards, you will be receiving indices until the "End" command is given and you need to print the targets and the count of shot targets.

Every time you receive an index, you need to shoot the target on that index, if it is possiblie.

Everytime you shoot a target, its value becomes -1 and it is considered shot. Along with that you also need to:

  • all the other targets, which have greater values than your current target, with its value.
  • All the targets, which have less than or equal value to the shot target, you need to increase with its value.

Keep in mind that you can't shoot a target, which is already shot. You also can't increase or reduce a target, which is considered shot.

When you receive the "End" command, print the targets in their current state and the count of shot targets in the following format:

"Shot targets: {count} -> {target1} {target2}… {targetn}"

Input / Constraints

  • On the first line of you will receive a sequence of integers, separated by a single space – the targets sequence.
  • On the next lines, until the "End"command you be receiving integers each on a single line – the index of the target to be shot.

Output

  • The format of the output is described above in the problem description.

Examples

Input

Output

Comments

24 50 36 70

0

4

3

1

End

Shot targets 3 -> -1 -1 130 -1

First we shoot target on index 0. It becomes equal to -1 and we start going through the rest of the targets. Since 50 is more than 24, we reduce it to 26 and 36 to 12 and 70 to 46. The sequence looks like that:

-1 26 12 46

The next index is invalid, so we don't do anything. Index 3 is valid and after the operations our sequence should look like that:

-1 72 58 -1

Then we take the first index with value 72 and our sequence looks like that:

-1 -1 130 -1

Then we print the result after the "End" command.

Тагове:
0
Fundamentals Module
plamenovd0 avatar plamenovd0 101 Точки
Best Answer

Здравей ето решението на задачата https://pastebin.com/antpVUtd. Що се отнася до работата с индекси използваш [] примерно:

let array = [1, 5, 10];

array[1] //5
0
MariqnK1 avatar MariqnK1 52 Точки

Благодаря. Знам как да работя с индекси по този начи, просто си представях съвсем друго решение. :)

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