ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1345. HTML

Hint: use regexps (+)
Posted by ASK 29 Mar 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).