#C4480. Smart Indentation
Smart Indentation
Smart Indentation
In many programming languages, code blocks are defined by special markers. In this problem, you are given a code snippet in which block starts and ends are explicitly marked by the tokens START_BLOCK;
and END_BLOCK;
. Your task is to adjust the indentation of each line according to the following smart indent rules:
- If a line, after trimming, equals
END_BLOCK;
, the indentation level is decreased by one before printing the line. - The line is then printed with an indentation of 4 spaces per level.
- If a line, after trimming, equals
START_BLOCK;
, the indentation level is increased by one after printing the line.
Formally, if we denote the current indentation level by \( l \), each line is printed as follows:
[ \text{OutputLine} = \underbrace{\texttt{ } ; \texttt{...}; \texttt{ }}_{l \text{ times}} + \text{trimmed_line} ]
Please note that the input will be given through standard input (stdin) and your output should be written to standard output (stdout). Also, the first number of the input indicates the number of test cases. For each test case, the first number is the number of lines in that test case followed by those lines.
inputFormat
The input is read from stdin with the following format:
- An integer T representing the number of test cases.
- For each test case:
- An integer N representing the number of lines in the code snippet.
- N lines follow, each representing a line of code. The lines may contain extra spaces that need to be corrected.
outputFormat
For each test case, output the adjusted code lines to stdout. Each line must be printed on a new line with the correct indentation. After each test case, print an empty line.
## sample1
3
START_BLOCK;
statement1;
END_BLOCK;
START_BLOCK;
statement1;
END_BLOCK;
</p>