Професионална програма
Loading...
Dianov avatar Dianov 8 Точки

Nested Loops - Lab (05. Travelling)

Здравейте!
Имам малък проблем с тестването на задачата от заглавието на темата. Нулевите тестове и част от останалите са наред, но на тест 5, 7, 9 и 10 Judge ми се кара с "Runtime error". Някой би ли ми обяснил какъв може да е проблемът, заради който гърми на тези тестове?

https://pastebin.com/a13dA5da

Благодаря предварително на всички!

0
Programming Basics with C#
Dianov:
При промяна на всички "int" -> "double" изчезват грешките. В условието не е упоменато какви числа се използват и всички примери са дадени с цели числа, откъдето идва грешката при решение с int.
Axiomatik avatar Axiomatik 1626 Точки
using System;

namespace Traveling

{
    class Program
    {
        static void Main(string[] args)
        {
            int sum = 0;

            //while (destination != "End")
            while (true)
            {
                string destination = Console.ReadLine();

                if (destination == "End" || destination == "")
                {
                    return;
                    //Environment.Exit(0);
                }

                int neededMoney = int.Parse(Console.ReadLine());

                while (true)
                {
                    int input = int.Parse(Console.ReadLine());
                    sum += input;

                    if (sum >= neededMoney)
                    {
                        Console.WriteLine($"Going to {destination}!");
                        sum = 0;
                        break;
                        //neededMoney = int.Parse(Console.ReadLine());
                    }
                }
                //destination = Console.ReadLine();
            }
        }
    }
}

Best,

0
Dianov avatar Dianov 8 Точки

Thanks for the answer! Your code still gives the same error on test 7, 9 and 10. Also as I can see the logic is the same as mine but written in 2 "while" cycles. It is working in Visual Studio but i'm interested what's the cause for these Runtime errors in Judge system.

0
Axiomatik avatar Axiomatik 1626 Точки

I think for this exercise int numeric values does not work and needs to be replaced with either double or decimal. Future exercises might have the same problem, so always try double/decimal instead of int.

Best,

0
30/12/2020 20:54:19
Dianov avatar Dianov 8 Точки

I wrote the same logic differently and there were the same errors in the same places. When changed all numeric variables to "double" - it worked! In the task conditions it isn't said that it mustn't be used integers and all the examples are given with integers yet we have found that this is the actual problem. Thanks a lot, buddy!

https://pastebin.com/vVcB0Uvy -> that's the final decision that get's 100/100 in Judge.

0