#P8032. [COCI 2015/2016 #7] Nizovi

[COCI 2015/2016 #7] Nizovi

Problem Description

Arrays in a programming language are defined as follows:

  • The beginning and end of an array are marked with curly braces ({\texttt \{ and }\texttt \}), respectively.
  • Inside each pair of braces, there are several (possibly 00) comma-separated elements (there is no comma after the last element of each array).
  • Each element can be either a word (a string consisting of lowercase letters) or another array.
  • Some valid arrays are: $\texttt {\{\}}, \texttt{\{a,b,c\}}, \texttt{\{abc,znj,\{novi,niz\},pozz\}}$.

You need to apply the following formatting style to make the program look nicer:

  • Start a new line whenever you encounter a word or a curly brace.
  • A comma should be placed directly after an array element.
  • Every time you encounter a {\texttt{\{}, increase the indentation by 22 spaces.
  • Every time you encounter a }\texttt{\}}, decrease the indentation by 22 spaces.

Given an array, output it in the above formatting style.

Input Format

A string SS representing the given array.

Output Format

The array formatted in the required style.

{abc,ono,sto}
{
  abc,
  ono,
  sto
}
{}
{
}
{znakovi}
{
  znakovi
}
{a,b,{c,d},e,{}}
{
  a,
  b,
  {
    c,
    d
  },
  e,
  {
  }
}

Hint

Constraints

  • For 50%50\% of the testdata, elements contain only words.
  • For 100%100\% of the testdata, 1S15001 \le |S| \le 1500.

Hints and Notes

The checker is from the Testlib library, see the attachment.

Translated from COCI 2015-2016 #7 Task 1 Nizovi.

The score for this problem follows the original COCI settings, with a full score of 5050.

Translated by ChatGPT 5