Can anyone give me any pointers as to any "tricks" for the input data when it comes to the starting position?
I've been using Java and constantly am getting RUNTIME ERROR when I submit, yet I have exactly correct answers when I run every example input posted on these boards, never once getting a RE.
I've used (by this point) Scanners, Regex, String.split(), Pattern, and even changed the input line to a character array and hand parsed it. No matter what I do, I keep getting a runtime error. With the judge, there's no way to tell which exception is being thrown so I can get a better idea of what the problem is, and without the input data being used to judge, I can't see what's being done that makes it fail.
Is the starting position being split over more than 1 line? I've put in, via Scanners or Regex or Patterns, the ability to handle any number of whitespace in between each portion. I've even gone so far as to assume that the A##[E|W] portion may not come first (even though it probably does - nothing in the spec stated they could be swapped). No matter what, I'm getting a RE.
Here's my most recent attempt at decoding the starting position (though this is iteration #20 or so, seriously):
Code: Select all
public location decodeLocation(String inline)
{
String pieces[];
int pmark = 0;
String subpieces[];
int smark = 0;
int dist = 0;
int pos = 0;
char dir;
location place = new location();
int value = 0;
// This should split the position line using whitespace delimiters
pieces = inline.split("\\s+");
// Choose the starting place, since any starting whitespace causes
// an "empty" token due to regex.
if (pieces[0].length() == 0)
pmark = 1;
else
pmark = 0;
// Do 1st piece...
// Split this subpiece based upon non-numeric delimiters
// (This should isolate just the street # portion
subpieces = pieces[pmark].split("\\D+");
// This shouldn't be needed, but I'm getting paranoid now...
if (subpieces[0].length() == 0)
smark = 1;
else
smark = 0;
// Convert the piece to a whole number...this isn't causing the RE
// (I thought perhaps it was a NumericFormat exception, so I commented
// this out earlier and still got RE)
dist = Integer.parseInt(subpieces[smark]);
// Set this value in my special class/struct to hold the distance
place.anx = dist;
// Do 2nd piece
pmark++;
subpieces = pieces[pmark].split("\\D+");
if (subpieces[0].length() == 0)
smark = 1;
else
smark = 0;
dist = Integer.parseInt(subpieces[smark]);
place.any = dist;
pmark++;
// Direction brought in
if (pieces[pmark].equals("N")) place.ahead = north;
if (pieces[pmark].equals("S")) place.ahead = south;
if (pieces[pmark].equals("E")) place.ahead = east;
if (pieces[pmark].equals("W")) place.ahead = west;
if (pieces[pmark].equals("NW")) place.ahead = nw;
if (pieces[pmark].equals("NE")) place.ahead = ne;
if (pieces[pmark].equals("SW")) place.ahead = sw;
if (pieces[pmark].equals("SE")) place.ahead = se;
return place;
}
Please note: This doesn't currently check to see if it should be northward, southward, eastward, or westward for either the avenue or street
Taking blind guesses as to the cause of the RE, I can only assume I'm overshooting the array size caused by the split() command. I wrapped all of that code above in a try-catch for an ArrayIndexOutOfBoundsException, forcing it to return a dummy location, and managed to get WA rather than RE -- so that tells me that my split() command is not giving me 3 (or 4 if there's an empty token due to prepended whitespace) tokens.
Did anyone else find that the starting position was split over two [or more] lines, or have an idea of what's going wrong here? Also, I'm checking ahead of time for the presence of "END" on the line and "STOP", along with blank lines in the input file, so I can't see how anything but the expected "A#[E|W] S#[N|S] [N|E|S|W|NE|NW|SE|SW]" is getting sent to this function.
Thanks for any help/tips!
Londovir