+ Нов въпрос
PikiMarinova 0 Точки

## Suitcases Load Online Exam 28 and 19 March

Здрявейте,

Бихте ли ми помогнали за тази задача?

На втория тест ми дава Runtime error и не мога да си обясня защо.

Ето кода:

using System;
using System.Numerics;

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

while (input != "End")
{
double suitcaseVolume = double.Parse(input);

if (suitcaseCounter + 1 % 3 == 0)
{
suitcaseVolume = suitcaseVolume * 1.1;
}

if (planeCapacity <= suitcaseVolume)
{
break;
}

suitcaseCounter++;
planeCapacity -= suitcaseVolume;

}

if (input == "End")
{
}
else
{
Console.WriteLine("No more space!");
}

}
}
}

Благодаря!

Тагове:
0
Axiomatik 100 Точки

This is one of those crazy exam-exercises where just the position of your Console.WriteLine can make or brake a test.

The only mistake I could find was that: if (suitcaseCounter + 1 % 3 == 0) needs to be included in additional brackets, like so : if ((suitcaseCounter + 1) % 3 == 0) . However, judge still doesn't give 100%, so I changed the position of the two Console.WriteLine to be positioned inside of the while-loop. CRAZY !!!

New code (100%):

using System;
using System.Numerics;

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

while (planeCapacity >= 0)
{
if (input == "End")
{
break;
}
double suitcaseVolume = double.Parse(input);

if ((suitcaseCounter + 1) % 3 == 0)
{
suitcaseVolume = suitcaseVolume * 1.1;
}

if (planeCapacity <= suitcaseVolume)
{
Console.WriteLine("No more space!");
break;
}

suitcaseCounter++;
planeCapacity -= suitcaseVolume;
}