Results 1 to 8 of 8
  1. #1
    Hayzam is offline Member
    Join Date
    May 2008
    Posts
    9
    Rep Power
    0

    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.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    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.

  3. #3
    Hayzam is offline Member
    Join Date
    May 2008
    Posts
    9
    Rep Power
    0

    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 ?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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. #5
    Hayzam is offline Member
    Join Date
    May 2008
    Posts
    9
    Rep Power
    0

    Default

    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. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,387
    Rep Power
    25

    Default

    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. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    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.

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Replies: 0
    Last Post: 02-14-2008, 10:00 AM
  2. image removing
    By Triss in forum New To Java
    Replies: 3
    Last Post: 01-20-2008, 08:27 PM
  3. Removing characters
    By kDude in forum New To Java
    Replies: 3
    Last Post: 12-03-2007, 02:38 AM
  4. removing duplicates from arrays
    By bugger in forum New To Java
    Replies: 3
    Last Post: 11-13-2007, 06:11 PM
  5. Help with removing somthing once inputed.
    By fegiflu in forum New To Java
    Replies: 8
    Last Post: 07-26-2007, 10:58 PM

Posting Permissions

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