Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-21-2008, 05:18 PM
Member
 
Join Date: May 2008
Posts: 9
Rep Power: 0
Hayzam is on a distinguished road
Default 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 ?!

Thanks in Advance

Last edited by Hayzam; 08-21-2008 at 05:42 PM.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 08-21-2008, 05:38 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 3,190
Rep Power: 5
Fubarable is on a distinguished road
Default
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.

Please clarify.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 08-21-2008, 05:44 PM
Member
 
Join Date: May 2008
Posts: 9
Rep Power: 0
Hayzam is on a distinguished road
Default
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 ?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 08-21-2008, 05:52 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 3,190
Rep Power: 5
Fubarable is on a distinguished road
Default
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.,
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.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 08-21-2008, 06:46 PM
Member
 
Join Date: May 2008
Posts: 9
Rep Power: 0
Hayzam is on a distinguished road
Default
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 ...
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 08-21-2008, 07:56 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Rep Power: 4
Norm is on a distinguished road
Default
Quote:
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
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 08-21-2008, 09:15 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 3,190
Rep Power: 5
Fubarable is on a distinguished road
Default
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.
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 08-21-2008, 10:02 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 3,190
Rep Power: 5
Fubarable is on a distinguished road
Default
Abuse reported on Cleaner007 for spamming the forums.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using escape sequence to find rows begining with % Java Tip Java Tips 0 02-14-2008 10:00 AM
image removing Triss New To Java 3 01-20-2008 08:27 PM
Removing characters kDude New To Java 3 12-03-2007 02:38 AM
removing duplicates from arrays bugger New To Java 3 11-13-2007 06:11 PM
Help with removing somthing once inputed. fegiflu New To Java 8 07-26-2007 10:58 PM


All times are GMT +2. The time now is 02:34 PM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org