K. Wiki Lists

Codeforces
IDCF10050K
Time1000ms
Memory64MB
Difficulty
English · Original
Formal · Original
In this task you need to write a small part of wiki-to-HTML translator. You have to deal only with enumerated and regular lists. Wiki dialect in this task defines lists as follows — the character "_#_" defines an enumerated list and "_*_" defines a regular list. These symbols are called list markers. Wiki-text should be processed line by line. A group of two or more consecutive lines should be treated as elements of the same list (enumerated, or regular) if these lines start with the same list marker symbol. A group of two or more consecutive list elements should be considered as a nested list if these elements start with the same list marker symbol. This rule should be applied recursively. HTML equivalent of a wiki-text is formed using the well-known HTML syntax. An enumerated list starts with "<ol>", then all list elements are written, and then the list ends with "</ol>". HTML equivalent of a regular list is similar to the one for enumerated list, but it starts with "<ul>" and ends with "</ul>". An element of any list is represented by "<li>", then the contents of the element are written followed by "</li>". The rules given above unambiguously define the way to make HTML from wiki-text. Please refer to the sample tests for clarifications. Input contains a wiki-text with no less than 1 and no more than 1000 lines. The total length of all input lines is not greater than 1000 characters. The depth of nested lists is not limited. Input contains only lowercase and uppercase Latin letters, digits, symbols "_*_" and "_#_", and line breaks. Each line contains at least one character different from "_*_" and "_#_", so there will be no empty lines in the output. Print HTML equivalent of the given wiki-text to the output. All tags should be placed on separate lines with no spaces. ## Input Input contains a wiki-text with no less than 1 and no more than 1000 lines. The total length of all input lines is not greater than 1000 characters. The depth of nested lists is not limited. Input contains only lowercase and uppercase Latin letters, digits, symbols "_*_" and "_#_", and line breaks. Each line contains at least one character different from "_*_" and "_#_", so there will be no empty lines in the output. ## Output Print HTML equivalent of the given wiki-text to the output. All tags should be placed on separate lines with no spaces. [samples]
**Definitions** Let $ L = (l_1, l_2, \dots, l_n) $ be a sequence of $ n $ lines of wiki-text, where each $ l_i $ is a string over the alphabet $ \Sigma = \{ \text{a-z}, \text{A-Z}, \text{0-9}, \#, *, \text{newline} \} $, and each line contains at least one non-marker character. Let $ m_i \in \{ \#, * \} $ denote the **list marker** of line $ l_i $, defined as the first non-whitespace character of $ l_i $ (guaranteed to be `#` or `*`). Let $ c_i \in \Sigma^* $ denote the **content** of line $ l_i $, defined as the substring of $ l_i $ starting from the first non-marker character to the end of the line. **Constraints** 1. $ 1 \le n \le 1000 $ 2. Total length of all $ l_i $ is $ \le 1000 $ characters 3. Each $ l_i $ contains at least one non-marker character 4. No empty lines **Objective** Transform $ L $ into an HTML string $ H $, structured recursively as follows: - A **maximal consecutive group** of lines $ l_i, l_{i+1}, \dots, l_j $ with the **same marker** $ m $ and **same indentation level** (i.e., no change in marker prefix depth) forms a **list** of type: - $ \texttt{<ol>} $ if $ m = \# $, - $ \texttt{<ul>} $ if $ m = * $. - Each list element is wrapped in $ \texttt{<li>} \dots \texttt{</li>} $, with content $ c_i $. - **Nested lists** arise when a group of consecutive lines has a **marker prefix** that is a **strict extension** of the parent’s marker (i.e., more leading markers than parent). - **Recursion rule**: - A line $ l_i $ is a child of the most recent preceding list element with **strictly fewer markers**. - The nesting structure is determined by the **number of leading markers** in each line. - Each list must be closed immediately after its last child element. **Output** Generate $ H $, a sequence of HTML tags and content, each tag or line of content on a separate line, with **no spaces**, satisfying the above nesting rules.
API Response (JSON)
{
  "problem": {
    "name": "K. Wiki Lists",
    "description": {
      "content": "In this task you need to write a small part of wiki-to-HTML translator. You have to deal only with enumerated and regular lists. Wiki dialect in this task defines lists as follows — the character \"_#",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 65536
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10050K"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "In this task you need to write a small part of wiki-to-HTML translator. You have to deal only with enumerated and regular lists.\n\nWiki dialect in this task defines lists as follows — the character \"_#...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ L = (l_1, l_2, \\dots, l_n) $ be a sequence of $ n $ lines of wiki-text, where each $ l_i $ is a string over the alphabet $ \\Sigma = \\{ \\text{a-z}, \\text{A-Z}, \\text{0-9}, \\#, *...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments