#P8032. Array Pretty Printer

    ID: 21216 Type: Default 1000ms 256MiB

Array Pretty Printer

Array Pretty Printer

Given a string representing an array in a programming language with the following properties:

  • The array starts with a left curly brace (\texttt{{}) and ends with a right curly brace (\texttt{}}).
  • Inside the braces there are zero or more elements separated by commas (note: there is no trailing comma after the final element).
  • Each element is either a word (a string of lowercase letters) or another array (defined recursively).

Some valid arrays include: (\texttt{{}}), (\texttt{{a,b,c}}), and (\texttt{{abc,znj,{novi,niz},pozz}}).

Your task is to reformat the given array string according to the following styling guidelines:

  1. Every time you encounter a word or a curly brace, start a new line.
  2. A comma should immediately follow the printed array element (i.e. remain on the same line as the element).
  3. Upon encountering a left curly brace (\texttt{{}), increase the indentation by 2 spaces.
  4. Upon encountering a right curly brace (\texttt{}}), decrease the indentation by 2 spaces.

Output the reformatted array string complying with the above formatting rules.

inputFormat

The input consists of a single line containing the array string.

outputFormat

Output the reformatted version of the array string following the specified code style. Ensure that each element or curly brace appears on a new line with the correct indentation.

sample

{}
{

}

</p>