import java.util.Scanner;
public class Main {
static int stack[] = new int[100];
static int pos = 0;
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
int m;
char arr[] = new char[101];
int i, j;
m = scan.nextInt();
for (i = 0; i < m; i++) {
arr[i] = scan.next().charAt(0);
if (Character.isDigit(arr[i])) {
push(arr[i]-'0');
}
else {
int a = pop();
int b = pop();
if (arr[i] == '+') {
push(a + b);
}
if (arr[i] == '-') {
push(b - a);
}
if (arr[i] == '*') {
push(a * b);
}
if (arr[i] == '/') {
push(b / a);
}
}
}
System.out.print(pop());
}
public static void push(int a) {
stack[pos++] = a;
}
public static int pop() {
return stack[--pos];
}
public static boolean isEmpty() {
return pos == 0;
}
}
http://www.jungol.co.kr/bbs/board.php?bo_table=pbank&wr_id=504&sca=2070
'정올문제소스코드' 카테고리의 다른 글
1309 : 팩토리얼 (0) | 2021.12.05 |
---|---|
2858 : 쇠막대기 (0) | 2021.12.05 |
1814 : 삽입정렬 횟수 세기 (0) | 2021.12.05 |
1157 : 버블정렬 (0) | 2021.12.05 |
1158 : 삽입정렬 (0) | 2021.12.05 |