#P1957. 口算练习题

口算练习题

Description

Teacher Wang is teaching simple arithmetic. The meticulous Teacher Wang has collected ii 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 5+8\texttt{5+8}, it is best to input only 5\texttt{5} and 8\texttt{8}. The output should be as detailed as possible to facilitate later typesetting; for instance, after processing the above input, output 5+8=13\texttt{5+8=13} and the total length of this expression, 66. Teacher Wang assigns you this task. Please write a program to implement the above functionality.

Input Format

The first line contains an integer ii.

The next ii 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: a\texttt{a} means addition, b\texttt{b} means subtraction, and c\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×i2 \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.

4
a 64 46
275 125
c 11 99
b 46 64

64+46=110
9
275+125=400
11
11*99=1089
10
46-64=-18
9

Hint

Constraints and Notes:

  • For 50%50\% of the testdata, each input expression has three data items.
  • For all testdata, 0<i500 < i \leq 50. The first expression always has three data items. Operands are non-negative integers less than 1000010000.

Translated by ChatGPT 5