Configuration File
InterviewTime limit2sMemory limit512 MB
Parse a brace-delimited configuration file where assignments to variables are scoped to their block, and report the value assigned by each variable-to-variable assignment.
- Level
Medium5 of 10
- Topics
- Stack, Hash map, Implementation, Simulation
- Solved
- No attempts yet
Problem
Vadim is developing a parser for the configuration files of his project. A configuration file consists of blocks delimited by braces: "{" marks the beginning of a block, and "}" marks the end of a block. Blocks can be nested. One block can contain several other blocks.
There are variables in the configuration file. Each variable has a name that consists of at most ten lowercase English letters. Each variable has an integer value, and initially all variables are set to .
New values can be assigned to variables. Assigning a constant value to a variable is written as "<variable>=<number>", where <variable> is the variable's name and <number> is an integer whose absolute value does not exceed . The parser reads the file line by line. When it reads an assignment operation, it assigns the new value to the variable. This value is used until the end of the current block, after which the previous value is restored. If the current block has nested blocks following the assignment, the new value of the variable is used inside those blocks.
A variable can also be assigned the value of another variable. Such an operation is written as "<variable1>=<variable2>". When the parser reads such a line, it assigns the current value of variable2 to variable1. As with assigning a constant value, the new value is used until the end of the current block. After the end of the current block, the value that the variable had at the beginning of the block is restored.
For debugging purposes, Vadim wants to print all values that are assigned when processing lines of the form "<variable1>=<variable2>". Help him debug the parser.
Input
The input contains at least and at most lines. Each line has one of four types:
{: beginning of a block;- }: end of a block;
<variable>=<number>: assigning a constant value to a variable;<variable1>=<variable2>: assigning one variable to another, where<variable1>and<variable2>can be the same.
The input is guaranteed to be correct and to match the statement. The input contains no spaces.
Output
For each line of the form "<variable1>=<variable2>", print the value that is assigned.