Loading...

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

Elena123456 avatar Elena123456 235 Точки

Man O War - Mid Exam Retake - 6 August 2019

I apologize, but can somebody please tell me why my code is not working? I have watched video lecture about this exercise https://softuni.bg/trainings/resources/video/44085/video-30-october-2019-slavi-kapsalov-csharp-fundamentals-september-2019/2438 , debugging and looked through all the code of my colleagues and result is 80/100. I can't understand how I scored only 80/100 for this exercise only if tests in Judge have been changed.

 Man O War:  https://judge.softuni.bg/Contests/Practice/Index/1773#2

 

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

namespace midExam
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            List<int> PirateShip = Console.ReadLine().Split('>').Select(int.Parse).ToList();
            List<int> WarShip = Console.ReadLine().Split('>').Select(int.Parse).ToList();
            int maxHealthCapacity = int.Parse(Console.ReadLine());
            string command = string.Empty;
            while ((command = Console.ReadLine()) != "Retire")
            {
                string[] commandArray = command.Split();

                if (commandArray[0] == "Fire")
                {
                    int index = int.Parse(commandArray[1]);
                    int damage = int.Parse(commandArray[2]);
                    if (index >= 0 && index <= PirateShip.Count - 1 && index <= WarShip.Count - 1)
                    {
                        WarShip[index] = WarShip[index] - damage;
                        if (WarShip[index] <= 0)
                        {
                            Console.WriteLine("You won! The enemy ship has sunken");
                            return;
                        }
                    }
                }

                else if (commandArray[0] == "Defend")
                {
                    int startIndex = int.Parse(commandArray[1]);
                    int endIndex = int.Parse(commandArray[2]);
                    int damage = int.Parse(commandArray[3]);

                    if (startIndex >= 0 && startIndex<=PirateShip.Count-1 && endIndex>=0 && endIndex <= PirateShip.Count - 1)
                    {
                        for (int i = startIndex; i <= endIndex; i++)
                        {
                            PirateShip[i] = PirateShip[i] - damage;
                            if (PirateShip[i] <= 0)
                            {
                                Console.WriteLine("You lost! The pirate ship has sunken.");
                                return;
                            }
                        }
                    }
                }

                else if (commandArray[0] == "Repair")
                {
                    int index = int.Parse(commandArray[1]);
                    int health = int.Parse(commandArray[2]);
                    if (index >= 0 && index <= PirateShip.Count - 1)
                    {
                        PirateShip[index] = PirateShip[index] + health;
                        if (PirateShip[index] > maxHealthCapacity)
                        {
                            PirateShip[index] = maxHealthCapacity;
                        }
                    }
                }

                else if (commandArray[0] == "Status")
                {
                    var filteredList = PirateShip.Where(x => (double) x / maxHealthCapacity * 100 < 20);
                    Console.WriteLine($"{filteredList.Count()} sections need repair.");
                }
            }

            Console.WriteLine($"Pirate ship status: {PirateShip.Sum()}");
            Console.WriteLine($"Warship status: {WarShip.Sum()}");
        }
    }
}

 

Тагове:
0
C# Fundamentals 09/10/2020 16:38:19
DimitarKazakov avatar DimitarKazakov 17 Точки

You have to print these two lines - 

Console.WriteLine($"Pirate ship status: {PirateShip.Sum()}");

  Console.WriteLine($"Warship status: {WarShip.Sum()}");

only when your ship has sank.

1
Elena123456 avatar Elena123456 235 Точки

Thanks for your feedback!

I haven't done this, because according the requirement I have to print the status of both ships if a stalemate occurs, which is the sum. If same ship win I have to print the winer and stop the program.

Tomorrow I would be trying your solution. Thanks again.

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