P1957 Mental Calculation Exercises

Description

Teacher Wang is teaching simple arithmetic. The meticulous Teacher Wang has collected $i$ mental calculation problems that students often get wrong and wants to compile them into a practice set. Laying out these problems is tedious, so he wants to use a computer program to improve efficiency. He hopes to minimize the input workload; for example, for the expression $\texttt{5+8}$, it is best to input only $\texttt{5}$ and $\texttt{8}$. The output should be as detailed as possible to facilitate later typesetting; for instance, after processing the above input, output $\texttt{5+8=13}$ and the total length of this expression, $6$. Teacher Wang assigns you this task. Please write a program to implement the above functionality.

Input Format

The first line contains an integer $i$. The next $i$ lines each describe an expression. Each line may contain either three data items or two data items. - If a line has three data items, then the first item is the operation type: $\texttt{a}$ means addition, $\texttt{b}$ means subtraction, and $\texttt{c}$ means multiplication. The next two items are the operands. - If a line has two data items, then the operation type is the same as in the previous problem, and these two items are the operands.

Output Format

Output $2 \times i$ lines. For each input expression, output the complete expression with its result on the first line. On the second line, output the total length of that expression.

Explanation/Hint

Constraints and Notes: - For $50\%$ of the testdata, each input expression has three data items. - For all testdata, $0 < i \leq 50$. The first expression always has three data items. Operands are non-negative integers less than $10000$. Translated by ChatGPT 5