[BOJ 9170] Single Digit Adder
View as PDF
Submit solution
Assembly, Awk, C, C++, Java, Pascal, Perl, Python, Sed, Text
Points:
2
Time limit:
1.0s
Memory limit:
128M
Problem type
Allowed languages
Write a program that can evaluate expressions from the following roughly BNF (Backus Naur Form) grammar:</p>
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.</p>
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
Comments