import java.util.ArrayList;
import java.util.List;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String sb = sc.nextLine();
System.out.println(getIn(sb));
}
private static int pos=0;
public static int getIn(String sb){
//递归之前方法栈保存各个节点的参数
Stack<Integer> stack = new Stack<>();
char opt='+';
int num =0;
while (pos<sb.length()){
if ('('==sb.charAt(pos)){
pos++;
num=getIn(sb);
}
while (pos<sb.length()&&Character.isDigit(sb.charAt(pos))){
num=num*10+sb.charAt(pos)-'0';
pos++;
}
if (opt=='+') stack.push(num);
if (opt=='-') stack.push(-num);
if (opt=='*') stack.push(stack.pop()*num);
num=0;
if (pos<sb.length()&&sb.charAt(pos)==')'){
pos++;
break;
}else if (pos<sb.length()){
opt=sb.charAt(pos);
pos++;
}
}
int sum =0;
while (!stack.isEmpty()){
sum+=stack.pop();
}
return sum;
}}

京公网安备 11010502036488号