Skip to content

Commit ee7601f

Browse files
authored
[BOJ] 15815 천재 수학자 성필 (S3)
1 parent d67ba39 commit ee7601f

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

정건우/11주차/260313.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//https://www.acmicpc.net/problem/15815
2+
import java.util.Scanner;
3+
import java.util.Stack;
4+
5+
public class BOJ_S3_15815_천재수학자성필 {
6+
7+
public static void main(String[] args) {
8+
Scanner scann = new Scanner(System.in);
9+
10+
String s = scann.nextLine();
11+
Stack<Long> stack = new Stack<>();
12+
13+
for (char c : s.toCharArray()) {
14+
if (Character.isDigit(c)) {
15+
stack.push((long)(c - '0'));
16+
} else {
17+
long op2 = stack.pop();
18+
long op1 = stack.pop();
19+
long res = 0;
20+
21+
switch (c) {
22+
case '+':
23+
res = op1 + op2;
24+
break;
25+
case '-':
26+
res = op1 - op2;
27+
break;
28+
case '*':
29+
res = op1 * op2;
30+
break;
31+
case '/':
32+
res = op1 / op2;
33+
break;
34+
default:
35+
break;
36+
}
37+
38+
stack.push(res);
39+
}
40+
41+
}
42+
43+
System.out.println(stack.pop());
44+
45+
}
46+
47+
}

0 commit comments

Comments
 (0)