|시간 제한||메모리 제한||제출||정답||맞힌 사람||정답 비율|
|1 초||256 MB||6||2||2||33.333%|
The ZOO management had been wondering for a long time how to increase the number of children visitors to the ZOO. The solution was surprising and unexpected in many ways. They installed a huge screen past the entrance and started to display short quizzes on it. The child in the crowd who first shouts out the answer to the quiz question is granted one day free access to the ZOO. The screen became soon very popular and various types of quizzes are routinely shown there. One type of the quiz is the math quiz containing arithmetic operations on integers. The management worries that older siblings and friends of the children might develop a math quiz screen hacking strategy: Snap the screen with the phone, run the image recognition SW which extracts formulas from the image, evaluates them, and presents the solution to the phone holder who immediately shouts out the answer.
Your task is to assess the difficulty of producing the screen hacking software. To get a better feel of the problem you will first develop a simple toy model application. Your code will read the formula presented in the preprocessed form of ASCII art and evaluate it.
There are multiple test cases. First line of each test case contains two integers R and C (1 ≤ R ≤ 3, 1 ≤ C ≤ 1 000). Each of the following R lines contains C characters. The whole matrix of R × C characters represents a single arithmetic formula written in ASCII art and generated by the following set of rules:
FORMULA -> COMPLEX | FORMULA + COMPLEX | FORMULA - COMPLEX COMPLEX -> SQRT | FRACTION | TERM ______ SQRT -> \/SIMPLE SIMPLE FRACTION -> ====== SIMPLE SIMPLE -> TERM | SIMPLE + TERM | SIMPLE - TERM TERM -> INTEGER | INTEGER * TERM INTEGER -> 0 | 1 | 2 | 3 | ... | 999999 | 1000000
There are also a few additional specifications regarding the layout of the formula.
SQRTis made of one or more underscore symbols (’ ’, ascii decimal code 95) and it always occupies the uppermost line of the formula in the screen.
SQRTparts of the formula.
TERMs and all arithmetic operation symbols which are not part of any
SQRToccupy the second line of the formula in the screen.
SQRTis the same as the length of
SIMPLEunder the bar.
FRACTIONconsists of one or more equality signs, its length is equal to the maximum of the lengths of
SIMPLEabove the bar and
SIMPLEbelow the bar.
The whole formula is evaluated according to the standard arithmetic rules. Namely: Each
FORMULA and each
TERM is evaluated from left to right. Each
SIMPLE is also evaluated from left to right with the additional standard condition that the multiplication has higher priority than the addition/subtraction. Evaluation of
FRACTION is also standard. The value of any evaluated
TERM is an integer whose absolute value does not exceed 1 000 000.
There is one empty line after each test case. The input is terminated by a line with two zeros.
For each test case print a separate line with the value V of the input formula.
1 13 1 + 2 * 3 - 4 2 16 _________ \/3 * 4 - 3 + 10 3 5 6 * 4 ===== 12 3 13 22 __ 3 - == - \/16 11 0 0
3 13 2 -3