packageStringSS;importjava.util.ArrayList;importjava.util.LinkedList;importjava.util.Queue;importjava.util.Scanner;importjava.util.Stack;/**
* @author 王永利
* @describe:
* @date 2024/02/25
*/publicclassCalculate{publicstaticvoidmain(String[] args){Scanner scanner =newScanner(System.in);String expreess = scanner.nextLine();// 方法String res =calculate(expreess);System.out.println(res);}publicstaticStringcalculate(String express){Queue<Character> queueF =newLinkedList<>();Queue<Integer> queueS =newLinkedList<>();char[] chars = express.toCharArray();for(int i =0; i < chars.length; i++){// 得到每个数字if(Character.isDigit(chars[i])){int num =0;while(i < express.length()&&Character.isDigit(chars[i])){
num = num *10+ chars[i]-'0';
i++;}if(((LinkedList<Character>) queueF).peekLast()=='*'){int a =((LinkedList<Integer>) queueS).pollLast();int b = num;int cal = a * b;((LinkedList<Character>) queueF).pollLast();
queueS.add(cal);}elseif(((LinkedList<Character>) queueF).peekLast()=='/'){int a =((LinkedList<Integer>) queueS).pollLast();int b = num;int cal = a / b;((LinkedList<Character>) queueF).pollLast();
queueS.add(cal);}
queueS.add(num);}if(!Character.isDigit(chars[i])){
queueF.add(chars[i]);}if(chars[i]=='/'){Integer a =((LinkedList<Integer>) queueS).pollLast();int b = chars[i+1]-'0';if(b ==0){return"error";}int mul = a * b;
queueS.add(mul);}if(chars[i]=='+'|| chars[i]=='-'){
queueF.add(chars[i]);}if(i ==0&& chars[i]>='0'&& chars[i]<='9'){
queueS.add(chars[i]-'0');}elseif(chars[i]>='0'&& chars[i]<='9'&& chars[i-1]!='*'&& chars[i-1]!='/'){
queueS.add(chars[i]-'0');}}if(queueF.isEmpty()){return queueS.poll().toString();}else{// 遍历计算栈中的+ -for(int i =0; i < queueF.size(); i++){int a =((LinkedList<Integer>) queueS).pollFirst();int b =((LinkedList<Integer>) queueS).pollFirst();int res;if(((LinkedList<Character>) queueF).get(i)=='+'){
res = a + b;}else{
res = a - b;}
queueS.add(res);}}return queueS.poll().toString();}}