QOJ.ac

QOJ

时间限制: 1 s 内存限制: 64 MB 总分: 50

#14591. NIZOVI

统计

在某种编程语言中,数组的定义方式如下:

  • 数组的开头和结尾分别用左大括号 { 和右大括号 } 表示。
  • 在大括号内部,有若干个(可能为 0 个)由逗号隔开的值(数组中的最后一个值后面没有逗号)。
  • 每个值可以是一个单词(由英文小写字母组成的字符串)或另一个数组。
  • 正确定义的数组示例:{}, {a,b,c}, {abc,znj,{novi,niz},pozz}

最近,你注意到该编程语言在花括号或逗号前后没有适当数量的空格和换行时不会报错。由于你觉得这些值“挤在一起”很不美观,你决定动手通过以下方式修改数组的排版格式:

  • 每个不是数组的值,以及表示数组开头或结尾的大括号({}),都必须独占一行。
  • 逗号与紧邻其前方的元素“相连”(即不换行),且每个逗号后面都要换行。
  • 在表示数组开头的左大括号 { 之后,内容的缩进增加 2 个空格(输出向右平移)。
  • 在表示数组结尾的右大括号 } 之前,内容的缩进减少 2 个空格(输出向左平移)。

输入格式

输入的第一行包含一个字符串 $S$($1 \le |S| \le 1500$),表示待格式化的数组。

输出格式

输出必须包含修改格式后的数组。

数据范围

对于 $50\%$ 的测试数据,数组中的所有值都是单词(即不存在嵌套数组)。

样例

输入样例 1

{abc,ono,sto}

输出样例 1

{
  abc,
  ono,
  sto
}

输入样例 2

{}

输出样例 2

{
}

输入样例 3

{znakovi}

输出样例 3

{
  znakovi
}

输入样例 4

{a,b,{c,d},e,{}}

输出样例 4

{
  a,
  b,
  {
    c,
    d
  },
  e,
  {
  }
}

说明

样例 4 解释:

最开始时,缩进为 0。在第一个左大括号之后,换行且缩进增加 2 个空格。

接着,输出单词 a 以及紧随其后的逗号,然后换行,保持 2 个空格的缩进。对单词 b 重复相同的步骤。

数组中的第三个值是一个新数组(我们称之为数组 $X$)。它以左大括号开头,因此我们需要换行并将缩进增加 2 个空格。此时总缩进为 4 个空格。在此缩进下,我们分别在独占的一行中输出单词 cd。在单词 d 之后没有逗号,因为它是数组 $X$ 中的最后一个值。

在输出表示数组 $X$ 结尾的右大括号之前,我们需要将缩进减少 2 个空格。在右大括号之后,我们输出逗号并换行,然后继续输出主数组中的值。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.