CF125B.Simple XML

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Let's define a string as an opening tag, where x is any small letter of the Latin alphabet. Each opening tag matches a closing tag of the type , where x is the same letter.

Tegs can be nested into each other: in this case one opening and closing tag pair is located inside another pair.

Let's define the notion of a XML-text:

  • an empty string is a XML-text
  • if s is a XML-text, then s'=+s+ also is a XML-text, where a is any small Latin letter
  • if _s_1, _s_2 are XML-texts, then _s_1+_s_2 also is a XML-text

You are given a XML-text (it is guaranteed that the text is valid), your task is to print in the following form:

  • each tag (opening and closing) is located on a single line
  • print before the tag 2 * h spaces, where h is the level of the tag's nestedness.

我们定义形如 <x> 的字符串为一个开始标签,其中 x 是任意一个小写的拉丁字母。每个开始标签都对应一个结束标签 </x>,其中 x 为相同的字母。

标签可以相互嵌套:此时一对开始与结束标签整体位于另一对开始与结束标签的内部。

我们定义 XML 文本如下:

  • 空字符串是一个 XML 文本;
  • 若 s 是一个 XML 文本,则 s'=+s+ 也是一个 XML 文本,其中 a 是任意一个小写的拉丁字母;
  • 若 _s_₁、_s_₂ 均为 XML 文本,则 _s_₁+_s_₂ 也是一个 XML 文本。

给定一个 XML 文本(保证该文本是合法的),你的任务是按如下格式输出:

  • 每个标签(包括开始标签和结束标签)独占一行;
  • 在每个标签前输出 2 \* _h_ 个空格,其中 h 为该标签的嵌套深度。

输入格式

The input data consists on the only non-empty string — the XML-text, its length does not exceed 1000 characters. It is guaranteed that the text is valid. The text contains no spaces.

输入数据仅包含一个非空字符串——XML 文本,其长度不超过 1000 个字符。保证该文本是合法的。文本中不包含空格。

输出格式

Print the given XML-text according to the above-given rules.

根据上述给定的规则,打印给定的 XML 文本。

输入输出样例

  • 输入#1

    &lt;a&gt;&lt;b&gt;&lt;c&gt;&lt;/c&gt;&lt;/b&gt;&lt;/a&gt;

    输出#1

    &lt;a&gt;
      &lt;b&gt;
        &lt;c&gt;
        &lt;/c&gt;
      &lt;/b&gt;
    &lt;/a&gt;
  • 输入#2

    &lt;a&gt;&lt;b&gt;&lt;/b&gt;&lt;d&gt;&lt;c&gt;&lt;/c&gt;&lt;/d&gt;&lt;/a&gt;

    输出#2

    &lt;a&gt;
      &lt;b&gt;
      &lt;/b&gt;
      &lt;d&gt;
        &lt;c&gt;
        &lt;/c&gt;
      &lt;/d&gt;
    &lt;/a&gt;

输入解题思路,AI测评打分。不知道怎么写?

首页