// Evan Machusak import java.util.*; import java.io.*; import java.awt.*; import java.text.*; public class Parser { private static void printError() { System.out.println("*****"); System.out.println("Error: Invalid Command"); System.out.println(); } private static boolean isWS(String s) { for (int i = 0; i < s.length(); i++) if (s.charAt(i) != ' ') return false; return true; } public static void main(String[] args) { long start = System.currentTimeMillis(); InputStreamReader rd = new InputStreamReader(System.in); BufferedReader console = new BufferedReader(rd); String inline; try { while ((inline = console.readLine()) != null) { // ---- BEGIN don't mess with ----- int i = 0; String[] line_ws = null; StringTokenizer tokenizer = new StringTokenizer(inline, "(,) ", true); line_ws = new String[tokenizer.countTokens()]; while (tokenizer.hasMoreTokens()) line_ws[i++] = tokenizer.nextToken(); int ws = 0; for (i = 0; i < line_ws.length; i++) if (isWS(line_ws[i]) == false) ws++; String[] line = new String[ws]; ws = 0; for (i = 0; i < line_ws.length; i++) if (isWS(line_ws[i]) == false) line[ws++] = line_ws[i]; // ---- END don't mess with ----- if (line.length > 0) { // You now have an array of strings, line[], which contains only relevant data and the punctuation () and , // example parsing: // tokens: [ CREATE_DOT ] [ ( ] [ name ] [ , ] [ 10 ] [ , ] [ 20 ] [ , ] [ 30 ] [ , ] [ red ] [ ) ] // index: 0 1 2 3 4 5 6 7 8 9 10 11 // first: look at line[0] and see which command it is // second: make sure the line length is correct. // third: make sure the data values are correct (try parsing ints where ints belong // fourth: check semantics (i.e., dot doesn't already exist, values are in range, etc) // fifth: print success or print error, based on #4 } } } catch (Exception e) { } System.out.println( "Running time (ms): " + (System.currentTimeMillis() - start)); } };