Професионална програма
Loading...
+ Нов въпрос
kostadin9009 avatar kostadin9009 3 Точки

Здравейте, може ли малко помощ, judge ми дава 90/100!

Може ли да ми погледнете кода, не мога да си открия грешката. Благодаря предварително. Ето го условието на задачата: https://judge.softuni.bg/Contests/Practice/Index/2028#1 . Ето го и моят код: https://pastebin.com/11j6XKFE 

 

Тагове:
0
C# Fundamentals
krasizorbov avatar krasizorbov 374 Точки

Ето твоето решение с 2 малки поправки! Когато здравето е под 0 излизаш от програмата с RETURN. В този случай isDead не ти трябва.

using System;
using System.Collections.Generic;
using System.Linq;
 
namespace _2._MuOnline
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] dungeonsRooms = Console.ReadLine().Split("|", StringSplitOptions.RemoveEmptyEntries).ToArray();
            int roomsCounter = 0;
            int initialHealth = 100;
            int bitcoins = 0;
            int totalBitcoins = 0;
            int currHealth = initialHealth;
            for (int i = 0; i < dungeonsRooms.Length; i++)
            {
                string[] tokens = dungeonsRooms[i].Split(" ", StringSplitOptions.RemoveEmptyEntries);
                string command = tokens[0];
                    switch (command)
                    {
 
                      case "potion":
                            roomsCounter++;
                            int amount = int.Parse(tokens[1]);
                       if (currHealth + amount <= 100)
                         {
                            currHealth += amount;
                        }
                        else if (currHealth + amount > 100)
                        {
                          int inHealth = currHealth;
                             currHealth = 100;
                           amount = currHealth - inHealth;

                           
                        }
                            Console.WriteLine($"You healed for {amount} hp.");
                            Console.WriteLine($"Current health: {currHealth} hp.");
                       
                            break;
 
                        case "chest":
                            roomsCounter++;
                            bitcoins = int.Parse(tokens[1]);
                            totalBitcoins += bitcoins;
                            Console.WriteLine($"You found {bitcoins} bitcoins.");
 
                            break;
 
                        default:
                            roomsCounter++;
                            amount = int.Parse(tokens[1]);
                            currHealth -= amount;
                            string monster = tokens[0];
                            if (currHealth <= 0)
                            {
                            Console.WriteLine($"You died! Killed by {monster}.");
                            Console.WriteLine($"Best room: {roomsCounter}");
                            return;
                            }
                            else
                            {
                            Console.WriteLine($"You slayed {monster}.");
                            }                          
                            break;
                    }
            }           
                Console.WriteLine("You've made it!");
                Console.WriteLine($"Bitcoins: {totalBitcoins}");
                Console.WriteLine($"Health: {currHealth}");
            
        }
    }
}

0
30/06/2020 16:03:32
kostadin9009 avatar kostadin9009 3 Точки

Какво ли не ми мина през главата, а то да се окаже нещо толкова просто на пръв поглед. Още веднъж благодаря !

0