Loading...

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

Mariofingarov avatar Mariofingarov 1 Точки

03. Heart Delivery

Здравейте колеги,

Имам затруднения със споменатата задача, Пробвах какво ли не, но повече от 70/100 не става. Всички изходи разбира се са така, четох условието и съм направил всичко стъпка, по- стъпка. Видях някои други решения, които имат 100/100 и пак не успявам да открия защо моя код не работи.

Условие: https://judge.softuni.bg/Contests/Practice/Index/2031#2

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

namespace _03.HeartDelivery
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> neededHearts = Console.ReadLine()
                .Split("@")
                .Select(int.Parse)
                .ToList();

            string input = Console.ReadLine();
            int currentPossition = 0;
            while (input != "Love!")
            {
                List<string> inputArg = input
                    .Split()
                    .ToList();
                currentPossition += int.Parse(inputArg[1]);

                if (currentPossition > neededHearts.Count - 1)
                {
                    currentPossition = 0;
                }
                if (neededHearts[currentPossition] == 0)
                {
                    Console.WriteLine($"Place {neededHearts[currentPossition]} already had Valentine's day.");
                }
                else
                {
                    neededHearts[currentPossition] -= 2;
                    if (neededHearts[currentPossition] == 0)
                    {
                        Console.WriteLine($"Place {currentPossition} has Valentine's day.");
                    }
                }
                input = Console.ReadLine();
            }
            Console.WriteLine($"Cupid's last position was {currentPossition}.");
            int counter = 0;
            for (int i = 0; i < neededHearts.Count; i++)
            {
                
                if (neededHearts[i] == 0)
                {
                    counter++;
                }
            }
            if (counter == neededHearts.Count)
            {
                Console.WriteLine("Mission was successful.");
            }
            else
            {
                Console.WriteLine($"Cupid has failed {neededHearts.Count - counter} places.");
            }
        }
    }
}

 

 

0
Fundamentals Module
milipt avatar milipt 10 Точки

И аз доста се въртях с тази задача. пробвай да броиш faild позициите на сърцата, а не колко са нулирани, да не би там нещо да се обърква.

int count =0;
        for (int i = 0; i < neighborhood.length; i++) {
                      if(neighborhood[i] !=0) {
                          count++;
                      }
        }
        if(count==0){
            System.out.println("Mission was successful.");
        }else{
            System.out.printf("Cupid has failed %d places.",count);
        }
 

0
Axiomatik avatar Axiomatik 2422 Точки

Everything was correct, just on line 38, you had to acutally print out the position on which Cupid is currently positioned and not the value of the selected house. For example, Cupid could be on index 2 and find a house that has 0 value, thus the output should be "Place 2 already had Valentine's day." and not "Place 0 already had Valentine's day."

Best,

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

namespace _03.HeartDelivery
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> neededHearts = Console.ReadLine()
                .Split("@")
                .Select(int.Parse)
                .ToList();

            string input = Console.ReadLine();
            int currentPossition = 0;

            while (input != "Love!")
            {
                List<string> inputArg = input
                    .Split()
                    .ToList();

                if (inputArg[0] == "Jump")
                {
                    currentPossition += int.Parse(inputArg[1]);
                }

                if (currentPossition > neededHearts.Count - 1)
                {
                    currentPossition = 0;
                }

                if (neededHearts[currentPossition] == 0)
                {
                    // THIS IS WHAT CAUSED THE ERROR
                    //Console.WriteLine($"Place {neededHearts[currentPossition]} already had Valentine's day.");
                    Console.WriteLine($"Place {currentPossition} already had Valentine's day.");
                }
                else
                {
                    neededHearts[currentPossition] -= 2;

                    if (neededHearts[currentPossition] == 0)
                    {
                        Console.WriteLine($"Place {currentPossition} has Valentine's day.");
                    }
                }
                input = Console.ReadLine();
            }

            Console.WriteLine($"Cupid's last position was {currentPossition}.");

            int counter = neededHearts
                .Count(h => h > 0);

            //for (int i = 0; i < neededHearts.Count; i++)
            //{
            //    if (neededHearts[i] == 0)
            //    {
            //        counter++;
            //    }
            //}

            //if (counter == neededHearts.Count)
            if (neededHearts.Sum() == 0)
            {
                Console.WriteLine("Mission was successful.");
            }
            else
            {
                Console.WriteLine($"Cupid has failed {counter} places.");
            }
        }
    }
}

1
Mariofingarov avatar Mariofingarov 1 Точки

Thank you a lot! Actually the wrong line was 31.

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