0145. Expression 1

Input file name: expr1.in
Output file name: expr1.out
Time limit: 2 s
Memory limit: 64 megabytes

Some background:

At one contest you were to write an integer expression evaluator. After thinking a while you thought this would be too easy problem for you, so as a fair contester you have contacted Jury and asked them to allow you writing the solution validation program in exchange for clarification papers WITHOUT 'no comments' checkbox. Well, by that time you did not know that these papers will simply return with 'no contest' checkbox checked since you were disqualified for such an effort: Anyway, by the time of writing that weird program you considered Jury to be as fair as you are.

The problem:

Now think of everything written above as in the past and now you are to write the level 2 validator: you must write solution validation program for the level 1 validator you have written before (see above description), i.e. you must write solution validator if the previous validator was itself a problem.

Let's get to the specs:
  1. Original expression problem:
    The original expression evaluation problem had to evaluate arbitrary valid integer expression involving +, -, *, /, brackets and integer numbers. There were no spaces. The input for the problem was a single line with this expression. This line could contain up to 100'000 characters. All integers were constants able to fit into 32bit signed integer. The expected output was the value of this expression on a single line. All operations had to obey saturation rules, i.e. when an overflow occurred, the value became the maximal possible positive integer that fits into 32bit signed integer and vice versa √ when an underflow occurs, the value becomes the least possible negative integer able to fit into 32bit signed integer. Division of negative value by zero implies -infinity as the result, division of positive value by zero implies +infinity as the result. Finally, 0/0 is considered to be 0 (Jury decided the medium integer value though all possible values would be a fair trade for 'any answer').
  2. Level 1 validator problem:
    The input for this validator consists of two lines. The first line is the input for the original problem. The second line is the output from the original problem. If the output value does not match the format that PASCAL 'write[ln]' or C 'printf("%d")' or C++ 'cout << (int)' can produce, the answer should be "Presentation Error" (w/o quotes). If the answer is a valid signed 32bit integer (i.e. it is not presentation error) but it differs from correct answer, level 1 validator has to output "Wrong answer, expected xxx" (w/o quotes again) where xxx is the expected output value. If the answer is valid and correct, just output "Accepted". See sample input/output of the whole problem for details.
  3. Level 2 validator (the one you are to write here in order to catch some minuses on the monitor, scare other teams and keep them off this problem).
    The input for this validator consists of three lines. The first line is the input for the original problem. The second line is the output from the original problem. The third line is the output from level 1 validator. Again, first you must check the format of the level 1 validator. If it is not "Accepted", "Presentation Error" or "Wrong answer, expected xxx", output "Presentation Error". Note that in case of the wrong answer you also must check that xxx obeys integer value rules described in the original problem. If it is not presentation error, check if the answer is correct (it is really presentation error of the original problem or it is really wrong answer and expected result is correct or it is really accepted). In this validator format for presentation error and accepted is the same as form the level 1 validator. For the wrong answer you must use format: Wrong answer, expected "yyy". Where yyy is correct output for level 1 validator. Note that quotes around yyy are significant. Again, check sample input and output to match the specs.
You must assume that the first line adheres expression rules described in the original problem. This means that you do not need to check if the expression is correct. Neither had the level 1 validator. However, the original problem solution output (2nd line of your input) and level 1 validator output (3rd line of your input) may contain almost anything. You may assume only one thing: output from both original solution and level 1 validator occupy exactly one line and do not have <CR> and <LF> characters inside. These characters appear only at the end of their lines and only in a single pair <CR><LF> and they should not be treated as part of their output.

Note that your solution will be tested differently. If you get "Presentation Error" this should be treated as wrong answer, wrong output file or something like this. Level 3 validator residing at the contest server will compare your answer against correct one only as a string of characters. So, if you write "Acccepted", most probably you will receive "Wrong Answer", NOT "Presentation Error".

Examples:

expr1.inexpr1.out
2+3 5 Accepted Accepted
(2) 3 Presentation Error Wrong answer, expected "Wrong answer, expected 2"
2+3 -05 Presentation errror Presentation error
2+3 5 I bet this stupid will not catch this error: Accepted Wrong answer, expected "Presentation error"


Source: Petrozavodsk Summer 2003. Trinity Contest, Tuesday, August 26
Author: Denis Koshman

Discuss       Submit a solution



Printable version