Back to General discussions forum

aleksandrhovhannisyan     2016-12-26 17:03:23

Hi,

I'm solving task #43, dice rolling, but it keeps telling me that my solution is wrong. Here is what I have:

``````            import java.util.*;

public class Solution
{
public static void main( String [] args )
{
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();

for( int i = 0; i < n; i++ )
{
System.out.print( (int)(n*scan.nextDouble()) + 1 + " " );
}
}
}
``````

I worked it out by hand, and it is in fact a correct solution. The results page shows the expected output in the range of 1-6 inclusive, but the problem clearly states that we are to multiply each input by n, not by 6, and then to add 1. Here's the input:

25 0.276709885802 0.623380549252 0.941141431686 0.439642432611 0.663952291477 0.285248592496 0.888164084405 0.134034371004 0.0431861043908 0.435089805629 0.687814481556 0.737287797034 0.833730780054 0.828572532628 0.249797360506 0.704544240143 0.907063114457 0.956651928369 0.158404618036 0.589289321098 0.893413713668 0.126149376854 0.842485802714 0.0133010083809 0.983667586464

And here is what I'm told is the correct output: 2 4 6 3 4 2 6 1 1 3 5 5 6 5 2 5 6 6 1 4 6 1 6 1 6

Quandray     2016-12-26 21:22:18

Hi,

While the problem description does say to multiply by n, that is closely followed by "in our case we multiply by 6".

The problem description says "Input data will contain the amount of values to convert in the first line", but it does not say that the first line contains n.

aleksandrhovhannisyan     2016-12-27 19:11:12

I see. However, the wording is quite misleading:

"Multiply random value by N which is the number of distinct values we want to get - in our case we multiply by 6"

When you say that "N" is the number of distinct values we want to get, that implies that "N" represents the number of (distinct) inputs. It doesn't help that the example below uses 6 input values, which makes it all the more misleading.

Please login and solve 5 problems to be able to post at forum