ENG  RUSTimus Online Judge
Online Judge
Online contests
About Online Judge
Frequently asked questions
Site news
Problem set
Submit solution
Judge status
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests

1345. HTML

Time limit: 1.0 second
Memory limit: 64 MB
Once a veteran of the ACM contests, thinking about the younger generation, decided to help them to master with the cobwebs of the sports programming. He decided to make an Internet site that would contain articles on programming, different interesting problems, solutions and the sources of those solutions. But his marvelous sources look faded and poor, not as they look in his favorite development framework: the key words are not emphasized, comments don’t differ from the other text... Nothing appeals to the eye.
He knows the basis of the HTML and he understands that it is a very unpleasant work to add coloring his sources tags manually.
- To write a program that adds tags is a duck soup! – he thought. – Or not a duck soup… May be it’ easier to do it manually… Or, may be… Eureka! If I can’t solve this problem, I’ll give it at the next ACM contest – some will surely solve the problem!… And if they make mistakes… Let them try!…


The correct source of a program in Pascal is given The length of the input text is not longer than 100 000 symbols.


You are to add formatting HTML tags so that the source text would look as it is required. The requirements are as follows:
  1. All the comments must be enclosed in the pair of tags “<span class=comment>” and “</span>”
  2. All the key words must be enclosed in the pair of tags “<span class=keyword>” and “</span>”
  3. All the strings must be enclosed in the pair of tags “<span class=string>” and “</span>”
  4. All the numbers must be enclosed in the pair of tags “<span class=number>” and “</span>”
  5. If key words, strings or numbers come upon the comments then they are assumed as a part of the comment and not as key words, strings or numbers.
  6. If key words, comments or numbers come upon the strings then they are assumed as a part of the string and not as key words, comments or numbers.
A string is the sequence of symbols enclosed in a pair of quotation marks “ ’ ” that does not contain other quotation marks. Or a symbol “#” which is followed by nonempty sequence of digits. In the second case it’s necessary to take the maximal sequence. E. g. in the sequence “#123” a subsequence “#1” is not a string and the entire sequence “#123” is a string.
A number begins with a digit and contains only digits and possibly one point “.”, followed by one or more digits. As in the case of a string a number is the maximal by inclusion sequence of symbols that satisfies the given above requirement.
An identifier may start with a letter or underscore (“_”) and contains letters, digits and underscores. As in the cases of strings and numbers, identifier is a maximal by inclusion sequence satisfying the given requirements.
There are comments of two types: comment of 1st type begins with ‘{’ and ends with ‘}’, both braces are the part of the comment; comment of 2nd type begins with ‘//’ and ends with line feed, slashes are the part of the comment while line feed is not. Nested comments are the part of the most outer comment.
Key words are the following identifiers: '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', 'with', 'while'.
Here every key word is enclosed in the pair quotation marks. The key words are given in the lower case but occur in any case in the text. E. g., ImPlEmentAtioN is a key word.


  writeln('Hello world!');
<span class=keyword>Begin</span>
  writeln(<span class=string>'Hello world!'</span>);
<span class=keyword>end</span>.


Many of you have guessed that if you save the result in a file output.html and to add in the beginning of the file the following lines:
    span.string {color: fuchsia;}
    span.number {color: darkblue;}
    span.keyword {font-weight: bold; color: black;}
    span.comment {font-style: italic; color: gray;}
and a line
in the end, then having opened this file in a browser you’ll see the input text with the colored syntax.
Problem Author: Pavel Egorov
Problem Source: USU Championship 2004