Проблем със задача Heart Delivery
Здравейте,
Получавам 60 точки и тъй като нулевите тестове минават нямам идея къде греша.
Моето решение: https://pastebin.com/xwqqCmug
Условие: https://judge.softuni.bg/Contests/Practice/Index/2031#2
Здравейте,
Получавам 60 точки и тъй като нулевите тестове минават нямам идея къде греша.
Моето решение: https://pastebin.com/xwqqCmug
Условие: https://judge.softuni.bg/Contests/Practice/Index/2031#2
Hi,
The problem in your code was between line 20-38, where the current position of Cupid was calculated.
Your code with new index-logic now gives 100% :
using System;
using System.Linq;
namespace Heart_Delivery
{
class Program
{
static void Main(string[] args)
{
int[] neighborhood = Console.ReadLine().Split("@").Select(int.Parse).ToArray();
string command = Console.ReadLine();
int lastPosition = 0;
while (command != "Love!")
{
string[] receivedCommand = command.Split();
int index = 0;
if (receivedCommand.Length > 0)
{
if (receivedCommand[0] == "Jump")
{
index = int.Parse(receivedCommand[1]);
}
}
while (index > 0)
{
lastPosition++;
if (lastPosition >= neighborhood.Length)
{
lastPosition = 0;
break;
}
index--;
}
if (neighborhood[lastPosition] == 0)
{
Console.WriteLine($"Place {lastPosition} already had Valentine's day.");
}
else
{
neighborhood[lastPosition] -= 2;
if (neighborhood[lastPosition] == 0)
{
Console.WriteLine($"Place {lastPosition} has Valentine's day.");
}
}
command = Console.ReadLine();
}
Console.WriteLine($"Cupid's last position was {lastPosition}.");
if (neighborhood.Sum() == 0)
{
Console.WriteLine($"Mission was successful.");
}
else
{
int houseCount = 0;
for (int i = 0; i < neighborhood.Length; i++)
{
if (neighborhood[i] != 0)
{
houseCount++;
}
}
Console.WriteLine($"Cupid has failed {houseCount} places.");
}
}
}
}
Does someone have any solution for this? kindly share your views dqfansurvey
Thank you!
I have solution with list for this exercise. I hope to help somebody for the exam preparation.
I think the name "Cupid" is taken from the name "Cupidon". :)
https://pastebin.com/rXdRecB7