P2366 yyy2015c01's IDE: Watches
Background
On a day in 2020, our classmate yyy2015c01 wanted to develop an IDE.
Description
As a member of his development team, you were unfortunately assigned to the Debugger group.
The Debugger envisioned by yyy2015c01 consists of several parts, and one small component is Watches — in Chinese, “变量观察器” (variable watcher).
Since the IDE is still in internal testing, the team needs a Watches that can monitor int-type variable values first to see how it works. This task is assigned to you.
The envisioned Watches can monitor the corresponding variable values after executing the following three types of statements:
- `n=1;` Assign a literal constant to a variable; the number of digits of this constant is at most $9$.
- `a=b;` Assignment between variables: if the source variable (in this example, $b$) has never been assigned, treat its initial value as $0$.
- `m=1+2;` Assignment with an $A+B$ expression. Only the `+` operator is allowed, and there are exactly two operands (either literals or variables). Both $A$ and $B$ are in the range $1$ to $10^6$.
Please implement a Watches that, after all statements are executed, outputs all variables that have been assigned at least once, in lexicographical order by identifier, along with their values (it is guaranteed that no variable’s value exceeds the maximum value of int).
Input Format
The input contains $n+1$ lines.
- The first line is a positive integer $n$, the number of assignment statements.
- Lines $2$ through $n+1$ each contain one assignment statement (in the format 'variable=expression;'). No extra characters will appear.
Output Format
Output one line for each variable that has been assigned at least once. Each line contains the variable identifier and its value. The variables must be sorted in lexicographical order by their identifiers.
Explanation/Hint
The testdata is very weak; direct simulation will pass.
(Don’t assume variable identifiers are single-character!)
Also, salute to the protagonist, classmate yyy2015c01!
Translated by ChatGPT 5