tonkatawe 3 Точки

Stacks and Queues - Key Revolver - 60/100

Здравейте колеги, моля за малко помощ защо джъджа ми дава 60/100, всички решения минават.. предполагам, че грешката е в някакви гранични стойности, но мисля, че съм направил всички възможни проверки (явно не съм де) :)

Линк към кода: https://pastebin.com/BJQdhkRt

Линк към задачата в judge: https://judge.softuni.bg/Contests/Practice/Index/1447#10

Условие:

*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 posesses 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, completely destroying it. Sam doesn’t know the size of the locks, so he needs to just shoot at all of them, until the safe runs 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 constaints 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.

Examples

 Input Output Comments 50 2 11 10 5 11 10 20 15 13 16 1500 Ping! Bang! Reloading! Bang! Bang! Reloading! 2 bullets left. Earned \$1300 20 shoots lock 15 (ping) 10 shoots lock 15 (bang) 11 shoots lock 13 (bang)  5 shoots lock 16 (bang)   Bullet cost: 4 * 50 = \$200 Earned: 1500 – 200 = \$1300 20 6 14 13 12 11 10 5 13 3 11 10 800 Bang! Ping! Ping! Ping! Ping! Ping! Couldn't get through. Locks left: 3 5 shoots lock 13 (bang) 10 shoots lock  3 (ping) 11 shoots lock  3 (ping) 12 shoots lock  3 (ping) 13 shoots lock  3 (ping) 14 shoots lock  3 (ping) 33 1 12 11 10 10 20 30 100 Bang! Reloading! Bang! Reloading! Bang! 0 bullets left. Earned \$1 10 shoots lock 10 (bang) 11 shoots lock 20 (bang) 12 shoots lock 30 (bang)   Bullet cost: 3 * 33 = \$99 Earned: 100 – 99 = \$1

Тагове:
0
nickwork 657 Точки

Махнах малко излишен код + пооправих някои работи

using System;
using System.Collections.Generic;
using System.Linq;

namespace WildFarm
{
public class StartUp
{
static void Main(string[] args)
{

var bulletStack = new Stack<int>(bullets); //going through the bullet back-to-front. In this case use LIFO
var locksQueue = new Queue<int>(locks); //shoot the lock from front-to-back. In this case use FIFO
var usedBullets = 0; //it is for counting of used bullets
var barrelCount = 0; //it is for checking when Sam need to reload

while (bulletStack.Any() && locksQueue.Any())
{

if (bulletStack.Peek() <= locksQueue.Peek()) //First Case if the bullet <= lock
{
Console.WriteLine("Bang!");
locksQueue.Dequeue();  //remove the lock
bulletStack.Pop(); //remove the bullet
}
else
{
Console.WriteLine("Ping!");
bulletStack.Pop();

}

barrelCount++;

if (barrelCount == sizeGunBarrel && bulletStack.Any())
{
barrelCount = 0;
}

usedBullets++;
}

if (bulletStack.Count >= 0 && locksQueue.Count == 0)
{
var earn = valueOfIntellegence - (usedBullets * bulletPrice);
Console.WriteLine(\$"{bulletStack.Count} bullets left. Earned \${earn}");
}
else
{
Console.WriteLine(\$"Couldn't get through. Locks left: {locksQueue.Count}");
}
}
}
}

0
tonkatawe 3 Точки

Благодаря и на двамата колеги :)

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