forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path2.java
More file actions
25 lines (20 loc) Β· 689 Bytes
/
2.java
File metadata and controls
25 lines (20 loc) Β· 689 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.next();
// 첫 λ²μ§Έ λ¬Έμλ₯Ό μ«μλ‘ λ³κ²½ν κ°μ λμ
long result = str.charAt(0) - '0';
for (int i = 1; i < str.length(); i++) {
// λ μ μ€μμ νλλΌλ '0' νΉμ '1'μΈ κ²½μ°, κ³±ν기보λ€λ λνκΈ° μν
int num = str.charAt(i) - '0';
if (num <= 1 || result <= 1) {
result += num;
}
else {
result *= num;
}
}
System.out.println(result);
}
}