Hint: use regexps (+)
Послано
ASK 29 мар 2010 22:47
Got AC with a 34-lines Java program.
5 lines for the RE:
"('[^']*'|#\\d+)|"+ // 1: str
"(\\d+(?:\\.\\d+)?)|"+ // 2: num
"(\\{[^}]*\\}|//[^\\r\\n]*)|"+ // 3: comment
"([a-z_][a-z_0-9]*)|"+ // 4: ID
"(.)" // 5: anything else
5 lines of kw:
{"and", "array", "begin", "case", "class", "const", "div", "do", "else", "end", "for",
"function", "if", "implementation", "interface", "mod", "not", "of", "or", "procedure",
"program", "record", "repeat", "shl", "shr", "string", "then", "to", "type", "unit",
"until", "uses", "var", "while", "with"};
and 10 copy/pasted lines of the main loop:
while in.findWithinHorizon is not null, check which group matched and print accordingly
Pitfalls:
The list of the keywords in the statement is not sorted and thus binarySearch in it fails.
The statement about "//..." comments is simply wrong: line feed is \n, in reality test 6 uses carriage-return (\r).