Counter Strike ?!? Mid Exam Retake 7 April 2020 C#
Здравейте, може ли някой да ми даде насоки за задачата и да ми каже къде бъркам?
Задачата - https://judge.softuni.bg/Contests/Practice/Index/2305#0
Моето решение - https://pastebin.com/MVRLnxC3 C#
Здравейте, може ли някой да ми даде насоки за задачата и да ми каже къде бъркам?
Задачата - https://judge.softuni.bg/Contests/Practice/Index/2305#0
Моето решение - https://pastebin.com/MVRLnxC3 C#
Two problems:
Line 20 : In output-message use remaining energy and not 0 for the final message.
Line 27-30 : Energy needs to be increased with the current round-counter, which is 3 at the first time, 6 the second time …
Best,
Refactored code (100%) :
using System;
namespace Counter_Strike
{
class Program
{
static void Main(string[] args)
{
int energy = int.Parse(Console.ReadLine());
string input = string.Empty;
int rountCounter = 0;
while ((input = Console.ReadLine()) != "End of battle")
{
int distance = int.Parse(input);
if (energy < distance)
{
Console.WriteLine($"Not enough energy! Game ends with {rountCounter} won battles and {energy} energy");
return;
}
rountCounter++;
energy -= distance;
if (rountCounter % 3 == 0)
{
energy += rountCounter;
}
}
Console.WriteLine($"Won battles: {rountCounter}. Energy left: {energy}");
}
}
}
Thank you!