C
C#14mo ago
Shunrai

✅ Help with Homework

I have an exercise for homework in order to practice. I have completed it to the extent of my abilities, however, one of the 10 run tests in the online platform does not provide the required output. Any ideas? :/
Tony and Andi love playing in the snow and having snowball fights, but they always argue about which makes the
best snowballs. They have decided to involve you in their fray by making you write a program, which calculates
snowball data and outputs the best snowball value.

You will receive N – an integer, the number of snowballs being made by Tony and Andi.
For each snowball you will receive 3 input lines:
• On the first line, you will get the snowballSnow – an integer.
• On the second line you will get the snowballTime – an integer.
• On the third line, you will get the snowballQuality – an integer.

For each snowball you must calculate its snowballValue by the following formula:
(snowballSnow / snowballTime) ^ snowballQuality
In the end, you must print the highest calculated snowballValue.

[Input]
• On the first input line, you will receive N – the number of snowballs.
• On the next N * 3 input lines, you will be receiving data about snowballs.

[Output]
• As output, you must print the highest calculated snowballValue, by the formula, specified above.
• The output format is:
{snowballSnow} : {snowballTime} = {snowballValue} ({snowballQuality})

[Constraints]
• The number of snowballs (N) will be an integer in the range [0…100].
• The snowballSnow is an integer in the range [0…1000].
• The snowballTime is an integer in the range [1…500].
• The snowballQuality is an integer in the range [0…100].
• Allowed working time/memory: 100ms / 16MB
Tony and Andi love playing in the snow and having snowball fights, but they always argue about which makes the
best snowballs. They have decided to involve you in their fray by making you write a program, which calculates
snowball data and outputs the best snowball value.

You will receive N – an integer, the number of snowballs being made by Tony and Andi.
For each snowball you will receive 3 input lines:
• On the first line, you will get the snowballSnow – an integer.
• On the second line you will get the snowballTime – an integer.
• On the third line, you will get the snowballQuality – an integer.

For each snowball you must calculate its snowballValue by the following formula:
(snowballSnow / snowballTime) ^ snowballQuality
In the end, you must print the highest calculated snowballValue.

[Input]
• On the first input line, you will receive N – the number of snowballs.
• On the next N * 3 input lines, you will be receiving data about snowballs.

[Output]
• As output, you must print the highest calculated snowballValue, by the formula, specified above.
• The output format is:
{snowballSnow} : {snowballTime} = {snowballValue} ({snowballQuality})

[Constraints]
• The number of snowballs (N) will be an integer in the range [0…100].
• The snowballSnow is an integer in the range [0…1000].
• The snowballTime is an integer in the range [1…500].
• The snowballQuality is an integer in the range [0…100].
• Allowed working time/memory: 100ms / 16MB
using System;

namespace _11.Snowballs
{
internal class Program
{
static void Main(string[] args)
{
int amount = int.Parse(Console.ReadLine());
double snowballHighestValue = double.MinValue;
int snowballHighestSnow = 0;
int snowballHighestTime = 0;
int snowballHighestQuality = 0;
for (int i = 1; i <= amount; i++)
{
int snow = int.Parse(Console.ReadLine());
int time = int.Parse(Console.ReadLine());
int quality = int.Parse(Console.ReadLine());
if (Math.Pow(snow / time, quality) > snowballHighestValue)
{
snowballHighestSnow = snow;
snowballHighestTime = time;
snowballHighestQuality = quality;
snowballHighestValue = Math.Pow(snow / time, quality);
}
}
Console.WriteLine($"{snowballHighestSnow} : {snowballHighestTime} = {snowballHighestValue} ({snowballHighestQuality})");
}
}
}
using System;

namespace _11.Snowballs
{
internal class Program
{
static void Main(string[] args)
{
int amount = int.Parse(Console.ReadLine());
double snowballHighestValue = double.MinValue;
int snowballHighestSnow = 0;
int snowballHighestTime = 0;
int snowballHighestQuality = 0;
for (int i = 1; i <= amount; i++)
{
int snow = int.Parse(Console.ReadLine());
int time = int.Parse(Console.ReadLine());
int quality = int.Parse(Console.ReadLine());
if (Math.Pow(snow / time, quality) > snowballHighestValue)
{
snowballHighestSnow = snow;
snowballHighestTime = time;
snowballHighestQuality = quality;
snowballHighestValue = Math.Pow(snow / time, quality);
}
}
Console.WriteLine($"{snowballHighestSnow} : {snowballHighestTime} = {snowballHighestValue} ({snowballHighestQuality})");
}
}
}
20 Replies
Shunrai
ShunraiOP14mo ago
(Some on the CW information is probably not correct, my only idea is that it has something to do with the math.pow logic. However, it seems to work fine for the ther 9 tests :/)
Angius
Angius14mo ago
Do you know what values does the non-passing test use?
Shunrai
ShunraiOP14mo ago
that's the issue, I don't I think I need alternative to double the value might be bigger than double can store
MODiX
MODiX14mo ago
Angius
REPL Result: Success
double.MaxValue
double.MaxValue
Result: double
1.7976931348623157E+308
1.7976931348623157E+308
Compile: 99.280ms | Execution: 11.396ms | React with ❌ to remove this embed.
Angius
Angius14mo ago
I doubt it
Shunrai
ShunraiOP14mo ago
tried decimal as well but math.pow can't do it with decimal and when I did (decimal)Math.Pow I get runtime error DogeKek
Angius
Angius14mo ago
I wonder if it goes over the alloted execution time...?
Shunrai
ShunraiOP14mo ago
it doesn't
Angius
Angius14mo ago
Try calculating the value just once instead of twice
Shunrai
ShunraiOP14mo ago
it gives a specific error if it does
Angius
Angius14mo ago
Huh
Shunrai
ShunraiOP14mo ago
on the website that I submit the code to so it's not the time that's an issue here 😦
Angius
Angius14mo ago
Yeah, no idea, everything seems perfectly fine
Shunrai
ShunraiOP14mo ago
Well @ZZZZZZZZZZZZZZZZZZZZZZZZZ apparently adding using System.Numerics; and making the value BigInteger instead of double and doing BigInteger.Pow fixed it. Only issue is i don't know why I don't think we have studied that 😐
Angius
Angius14mo ago
Huh I wonder if ulong would've worked Actually, I wonder if rounding the value and casting it to an int or uint would've worked
Shunrai
ShunraiOP14mo ago
doesn't tested now
Angius
Angius14mo ago
Perhaps, because of floating point rounding errors, the value sometimes is 813223.000000000032 or some such
Shunrai
ShunraiOP14mo ago
i have no idea at this point... Anyway Thank you very much for your ShuHug
Angius
Angius14mo ago
Anytime Ok
Accord
Accord14mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server