Thread: removing 0 from the begining of the array

1. Member
Join Date
May 2008
Posts
9
Rep Power
0

removing 0 from the begining of the array

well , in a problem I'm solving , i have to compare the lengths of 2 arrays ... if they have the same length it will do something , if they don't have it , it will do something else ..

but i failed in a test case that 1 array is 1988 and the other was 0908 ...

how can i remove 0 from the beginning of the array ?!

Last edited by Hayzam; 08-21-2008 at 05:42 PM.

2. I'm confused: are these supposed to act as Strings or as numbers? If numbers, then perhaps you should parse them as numbers first before comparing.

And how do arrays figure in here? You talk of comparing two arrays, but then in your example you talk of comparing two Strings.

3. Member
Join Date
May 2008
Posts
9
Rep Power
0
i am talking about comparing between 2 arrays from the length point of view ...

array1 = 1999
array2 = 0908

i would like to make array2 = 908 .. can you help me ?

4. Java Code:
```array1 = 1999
array2 = 0908```
again confusing because this just doesn't make sense. Sorry for being a stickler, but programming is an exercise in precision. If you have a question, you will be best served to communicate it as precisely as possible. Why not show us actual compilable Java code for your example.

e.g.,
Java Code:
```    // do you mean String?
String s1 = "1999";
String s2 = "0908";

// char array?
char[] charArray1 = s1.toCharArray();
char[] charArray2 = s2.toCharArray();

// ints?
int intValue1 = Integer.parseInt(s1);
int intValue2 = Integer.parseInt(s2);```
Last edited by Fubarable; 08-21-2008 at 05:55 PM.

5. Member
Join Date
May 2008
Posts
9
Rep Power
0
it is a problem was in the ACM 2007
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 ...

6. array1 = 1999
array2 = 0908

i would like to make array2 = 908 .. can you help me ?
Since the arrays appears to be a String of 4 chars, Then:
array2 = array2.substring(1); // drop leading char

7. actually it seems that he's working with int arrays. You could always check the [0] item to see if it == 0. If so, do an System.ArrayCopy, but don't copy the first item.

8. Abuse reported on Cleaner007 for spamming the forums.

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•