it is a problem was in the ACM 2007
|
Quote:
|
private static void Reverse_Hide_That_Number(int[] input_array)
{
int[] solution = new int[input_array.length];
int[] solution_shifted = new int[input_array.length+1];
int result,flag=0;
for(int i = solution.length;i>0;i--)
{
if(input_array[i-1] < solution_shifted[i])
{
solution[i-1] = input_array[i-1] + 10 - solution_shifted[i] - flag;
flag = 1;
}
else
{
solution[i-1] = input_array[i-1] - solution_shifted[i];
flag = 0;
}
solution_shifted[i-1] = solution[i-1];
}
// checking
if(input_array.length == solution.length -1)
{
// System.out.print(" Accepted ");
for(int i = 0;i<solution.length;i++)
{
// System.out.print(" output : "+ solution[i]);
System.out.print(solution[i]);
}
}
else
{
System.out.println(" IMPOSSIBLE ");
}
}
}
|
what i need is fixing the if statement at the end of the function to tell impossible if the length of the solution array = the length of the input_array ...