#P2395. BBCode转换Markdown
BBCode转换Markdown
Description
PDF version of the problem: http://pan.baidu.com/s/1i3mxk4t Extraction code hayc
2025-7-17: The link is down.
The syntax of BBCode is as follows:
[h1]Hello World![/h1]
[h2][i]This is a BBCode[/i][/h2]
[b][i]I love[/i] Olympic [i]Informatics[/i][/b]
For example, in the tag [h1], the content wrapped between [h1] and [/h1] is a level-1 heading, and the text within should be rendered in the style of a level-1 heading.
Please note that BBCode requires tags to be properly opened and closed and nested correctly, that is, the following examples are all invalid BBCode:
[h1]Hello World! // tag not closed
[h1]Hello World![/h2] // two tags do not match
[h1][i]Hello World![/h1][/i] // incorrect nesting order
In addition, a very important point is that BBCode has a special tag [quote][/quote]. Any text inside it should not be parsed as BBCode code but should be converted to Markdown and then output verbatim.
Now, introducing Markdown. Its syntax is as follows:
# Hello World! #
## *This is a Markdown* ##
__*I love* Olympic *Informatics*__
Your task is to convert a given piece of BBCode into Markdown and report errors for invalid input.
All BBCode tags that will appear in the testdata and their corresponding Markdown counterparts are shown below. No other mappings will appear:

Additional notes for the [quote] tag:

Input Format
The BBCode that needs to be converted.
[h1]Hello World![/h1]
[h2]How are [i]you[/i]?[/h2]
# Hello World! #
## How are *you*? ##
[h1]Introducing Swift.[/h1][quote]
import SpriteKit
let object = SKSpriteNode(imageNamed: “[L2/Ascention]”
[/quote]
# Introducing Swift. #
> import SpriteKit
> let object = SKSpriteNode(imageNamed: “[L2/Ascention]”
[h1]I knew you were
trouble when you walked in[/h1]
[url=http://www.example.com]By Taylor Swift[/url]
# I knew you were
trouble when you walked in #
[By Taylor Swift](http://www.example.com)
[h1]Thanks for [i]inviting[/h1] me.[/i]
Match Error
[h2]Your gift is awesome!
Unclosed Mark
[quote][/quote][/quote]
Match Error
(对该数据的解释: 匹配到第一个关闭标签后即不认为后面的内容仍是代码段)
[quote][quote][/quote]
> [quote]
Hint
To ensure smooth judging and avoid misjudgment, please pay attention to the following requirements:
- Respect the original line breaks in the input and output. Do not add or remove line breaks on your own.
- The exception to the above: when encountering a
[quote]tag that is not on a new line, please start a new line in Markdown. Also, please remove the leading and trailing blank lines of the code block inside the[quote]tag. There will be no empty quotes. - Please pay attention to the spaces in the table above.
- For invalid BBCode input, your program must report an error:
- For mismatched tags, output
Match Error. - For unclosed tags, output
Unclosed Mark. Please refer to the samples.
- For mismatched tags, output
- When both situations occur at the same time (that is, both a matching error and unclosed tags), handle it as a matching error and output
Match Error. - Due to the special nature of the quote tag, to avoid ambiguity, the testdata guarantees that the quote tag will not be erroneous.
- For example: for a case like
[i][h1]Text[/i], handle it asMatch Error. For a case like[i][h1]Text[/h1], handle it asUnclosed Mark. - Due to Luogu limitations, when outputting
Unclosed Mark, please splitclosein the middle into two separate strings, otherwise the record will be swallowed. - It is guaranteed that the following characters will not appear in text outside segments wrapped by the quote tag:
[]/*_#>. However, the/character may appear in URLs. - The input will not contain incomplete tags, such as
[h1]Text[/h. - For those who have used Markdown and BBCode elsewhere: the formats in this problem are not strictly the standard BBCode or Markdown formats. Please do not be misled by prior experience.
Translated by ChatGPT 5
京公网安备 11011102002149号