File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments