Loading...

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

ZhivkoMihalev avatar ZhivkoMihalev 3 Точки

11. Key Revolver 80/100 C#

Здравейте,

Както и да я въртя тази задача - все 80/100 ми дава. Реших я по два различни начина и все едно и също - явно изпускам нещо.

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

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

Поздрави!

https://pastebin.com/xqZuZQTP

11.*Key Revolver

Our favorite super-spy action hero Sam is back from his mission in another exam, and this time he has an even more difficult task. He needs to unlock a safe. The problem is that the safe is locked by several locks in a row, which all have varying sizes.

Our hero possesses a special weapon though, called the Key Revolver, with special bullets. Each bullet can unlock a lock with a size equal to or larger than the size of the bullet. The bullet goes into the keyhole, then explodes, destroying it. Sam doesn’t know the size of the locks, so he needs to just shoot at all of them until the safe run out of locks.

What’s behind the safe, you ask? Well, intelligence! It is told that Sam’s sworn enemy – Nikoladze, keeps his top-secret Georgian Chacha Brandy recipe inside. It’s valued differently across different times of the year, so Sam’s boss will tell him what it’s worth over the radio. One last thing, every bullet Sam fires will also cost him money, which will be deducted from his pay from the price of the intelligence.

Good luck, operative.

Input

  • On the first line of input, you will receive the price of each bullet – an integer in the range [0-100]
  • On the second line, you will receive the size of the gun barrel – an integer in the range [1-5000]
  • On the third line, you will receive the bullets – a space-separated integer sequence with [1-100] integers
  • On the fourth line, you will receive the locks – a space-separated integer sequence with [1-100] integers
  • On the fifth line, you will receive the value of the intelligence – an integer in the range [1-100000]

After Sam receives all of his information and gear (input), he starts to shoot the locks front-to-back, while going through the bullets back-to-front.

If the bullet has a smaller or equal size to the current lock, print "Bang!", then remove the lock. If not, print "Ping!", leaving the lock intact. The bullet is removed in both cases.

If Sam runs out of bullets in his barrel, print "Reloading!" on the console, then continue shooting. If there aren’t any bullets left, don’t print it.

The program ends when Sam either runs out of bullets, or the safe runs out of locks.

Output

  •  If Sam runs out of bullets before the safe runs out of locks, print:
    "Couldn't get through. Locks left: {locksLeft}"
  • If Sam manages to open the safe, print:
    "{bulletsLeft} bullets left. Earned ${moneyEarned}"

Make sure to account for the price of the bullets when calculating the money earned.

Constraints

  • The input will be within the constraints specified above and will always be valid. There is no need to check it explicitly.
  • There will never be a case where Sam breaks the lock and ends up with а negative balance.
Тагове:
0
Module: C# Advanced 18/02/2022 15:21:54
MartinBG avatar MartinBG 4803 Точки

Логиката беше ненужно усложнена и не покриваше всички възможни ситуации.

Ето оправеното решение. Питайте, ако има нещо неясно.

0
ZhivkoMihalev avatar ZhivkoMihalev 3 Точки

Благодаря за съдействието!

1
Dianov avatar Dianov 13 Точки

Ето и моето решение със C#. Успех!

https://github.com/DDianovMD/SoftUni/blob/main/CSharpAdvanced/StacksAndQueuesExercise/KeyRevolver/Program.cs

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