시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 | 128 MB | 102 | 55 | 42 | 52.500% |
Write a program that can evaluate expressions from the following roughly BNF (Backus Naur Form) grammar:
expr ::= term | expr ‘+’ term | expr ‘-’ term unary_op ::= ‘+’ term | ‘-’ term term ::= ‘(’ expr ‘)’ | ‘(’ unary_op ‘)’ | literal literal ::= [0-9]
There will be no whitespace within an expression. All expressions will consist solely of the characters (, ), +, -, and the digits 0 through 9. You may assume that all input is well-formed.
The input will consist of one expression per line followed by a newline. The length of expression does not exceed 200.
There will be no blank lines in the file.
For each expression, output its integer value, followed by a single newline.
1 (-2)+3 (1-(2+3)) (1-2+3) (1-(+(2-3)))
1 1 -4 2 2
ICPC > Regionals > North America > Pacific Northwest Regional > 2005 Pacific Northwest Region Programming Contest A번