codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

125B.md (1485B)


      1 Source: https://codeforces.com/problemset/problem/125/B
      2 
      3 B. Simple XML
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Let's define a string <x> as an opening tag, where *x* is any small letter of the Latin alphabet. Each opening tag matches a closing tag of the type </x>, where *x* is the same letter.
     22 
     23 Tegs can be nested into each other: in this case one opening and closing tag pair is located inside another pair.
     24 
     25 Let's define the notion of a XML-text:
     26 
     27 * an empty string is a XML-text
     28 * if *s* is a XML-text, then *s*'=<a>+*s*+</a> also is a XML-text, where *a* is any small Latin letter
     29 * if *s*1, *s*2 are XML-texts, then *s*1+*s*2 also is a XML-text
     30 
     31 You are given a XML-text (it is guaranteed that the text is valid), your task is to print in the following form:
     32 
     33 * each tag (opening and closing) is located on a single line
     34 * print before the tag 2 * *h* spaces, where *h* is the level of the tag's nestedness.
     35 
     36 Input
     37 
     38 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.
     39 
     40 Output
     41 
     42 Print the given XML-text according to the above-given rules.
     43 
     44 Examples
     45 
     46 Input
     47 
     48 ```
     49 <a><b><c></c></b></a>
     50 ```
     51 
     52 Output
     53 
     54 ```
     55 <a>  
     56   <b>  
     57     <c>  
     58     </c>  
     59   </b>  
     60 </a>
     61 ```
     62 
     63 Input
     64 
     65 ```
     66 <a><b></b><d><c></c></d></a>
     67 ```
     68 
     69 Output
     70 
     71 ```
     72 <a>  
     73   <b>  
     74   </b>  
     75   <d>  
     76     <c>  
     77     </c>  
     78   </d>  
     79 </a>
     80 ```