import java.util.*;
public class Main {
static Stack<Integer> stack = new Stack<>();
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String str = new String();
str = scan.nextLine();
int sum = 0;
boolean flag = false;
int num = 0;
for(int i = 0; i < str.length(); i++) {
if(str.charAt(i) == '@') {
break;
}else if(str.charAt(i) >= '0' && str.charAt(i) <= '9' || str.charAt(i) == '.') {
if(!flag) {
num = i;
flag = true;
continue;
}else if(str.charAt(i) == '.') {
stack.push(Integer.parseInt(str.substring(num, i)));
num = 0;
flag = false;
continue;
}
}else {
int a = stack.pop();
int b = stack.pop();
if(str.charAt(i) == '+') {
sum = b + a;
}else if(str.charAt(i) == '-') {
sum = b - a;
}
else if(str.charAt(i) == '/') {
sum = b / a;
}else if(str.charAt(i) == '*') {
sum = b * a;
}
stack.push(sum);
}
}
System.out.print(stack.pop());
}
}
洛谷 P1449 后缀表达式 Java
最新推荐文章于 2024-06-07 08:25:31 发布