I work in the publishing department of a science magazine. The editor-in-chief has just left me with a tedious task: process all scientific texts according to a new standard.
A
scientific text contains one or more paragraphs. A paragraph is a sequence of
characters ending with the end-of-line mark (newline character).
A reference is a positive integer between 1 and 99, listed between square brackets (e.g. [23]), without spaces between the number and the brackets. Square brackets are only used to mark references.
There are two types of paragraphs: regular paragraphs and reference description paragraphs.
A regular paragraph may contain any number of references.
A reference description paragraph differs from a regular paragraph because it
begins with the reference it describes and contains no other references within
it. E.g.:
[23] This is the description of...
The open square bracket is always on the first position of the reference description
paragraph.
There has to be a reference description paragraph for each reference appearing
in regular paragraphs. Also, every reference description paragraph must correspond
to one/some references appearing in regular paragraphs.
According
to the new standards a scientific text should follow the rules:
- references must be renumbered in the order of their first appearance in the
text, starting with 1;
- regular paragraph order is preserved;
- reference description paragraphs must all be located at the end of the text, in the order of the described references' numbers;
- no other changes in the text are accepted.
Task
Write a program that reads a scientific text and processes it according to the rules of the new standard.
Input data
Input file ref.in contains the scientific text to be processed.
Output data
Output file ref.out will contain the scientific text processed according to the new standard.
Constraints and clarifications
Example
ref.in | ref.out |
[44] reference description for 44 text 20 [20] text some other text 44 [44] text again 20 [20] [33] reference description for 33 regular paragraph 20 [20] regular paragraph 20 [20] [20] reference description for 20 regular paragraph 20 [20] regular paragraph 33 [33] regular paragraph 33 [33] regular paragraph 44 [44] |
text 20 [1] text some other text 44 [2] |
Time limit: 0.1 seconds/test
prof. Emanuela
Cerchez
Computer Science
High School "Grigore Moisil"Iasi
Contact:emanuela.cerchez@gmail.com