-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBOJ2011.java
More file actions
68 lines (57 loc) · 1.9 KB
/
BOJ2011.java
File metadata and controls
68 lines (57 loc) · 1.9 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class BOJ2011 {
/**
* 문제 거지 같아서 안품
*/
static String numStr;
static int dp[];
private static void input() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
numStr = br.readLine();
dp = new int[numStr.length()+1];
}
public static void main(String[] args) throws IOException {
input();
process();
}
private static void process(){
// set dp
// exception handling
if(Integer.parseInt(numStr.substring(0,1)) == 0){
System.out.println(0);
return;
}
if(numStr.length() == 1){
System.out.println(1);
return;
}
// set idx 1
dp[1] = 1;
// set idx 2
if(Integer.parseInt(numStr.substring(0,2)) > 0 && Integer.parseInt(numStr.substring(0,2)) <= 26 && Integer.parseInt(numStr.substring(0,2)) != 10 && Integer.parseInt(numStr.substring(0,2)) != 20)
dp[2] = 2;
else
dp[2] = 1;
for(int i = 3; i <= numStr.length(); i++){
int num = Integer.parseInt(numStr.substring(i-2, i));
// num > 26인 경우
if(num % 10 != 0 && num > 26)
dp[i] = dp[i-1] % 1000000;
// 0 < num <= 26인 경우
else if(num == 10 || num == 20)
dp[i] = dp[i-2] % 1000000;
else if(num > 0 && num <= 26)
dp[i] = (dp[i-2] + dp[i-1]) % 1000000;
// 나머지 0 출력 후 종료
else{
System.out.println(0);
return;
}
}
// print answer
System.out.println(dp[numStr.length()] % 1000000);
}
}