Calculator
Time Limit:1s | Memory limit:32M |
Accepted Submit:183 | Total Submit:577 |
Today the teacher give out a tedious homework to loy concerning the integer calculation practice. He is not contend with such boring homework, so instead, loy decides to write a program to help him finish the homework. The expression is consists of only integers,+,-,*,/,( and ). The brackets is guaranteed to be exactly matched. And the operator / returns the integer part of the division, i.e. 7/2=3. It is guaranteed that the divisor is not zero. Input The first line of the input contains a single integer t, representing the number of testcase. The following t lines contains expressions one per line. There is no extra spaces in the expression. And the total length of the expression will not exceed 200.Output For each case, output a integer representing the result of the expression.Sample Input 2 1+3/2 1-(2+(3*(4/5))) Sample Output 2 -1 Original: LOY
http://acm.fzu.edu.cn/problem.php?pid=1339
这一题用到的是逆波兰表达示,再用一个栈来存储转换后的波兰表表达示。再用一个栈来存放表达式运算后的结果
|