forked from priyanshu003/ImportantConcepts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprintEncoding.java
47 lines (39 loc) · 1.48 KB
/
printEncoding.java
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
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
printEncodings(str, "");
}
public static void printEncodings(String ques, String ans) {
if (ques.length() == 0) {
System.out.println(ans);
return;
} else if (ques.length() == 1) {
if (ques.charAt(0) == '0') {
return;
} else {
String ch0 = ques.substring(0, 1);
String roq0 = ques.substring(1);
String code0 = (char)('a' + (Integer.parseInt(ch0) - 1)) + "";
printEncodings(roq0, ans + code0);
}
} else {
if (ques.charAt(0) == '0') {
return;
} else {
String ch0 = ques.substring(0, 1);
String roq0 = ques.substring(1);
String code0 = (char)('a' + (Integer.parseInt(ch0) - 1)) + "";
printEncodings(roq0, ans + code0);
String ch01 = ques.substring(0, 2);
String roq01 = ques.substring(2);
String code01 = (char)('a' + (Integer.parseInt(ch01) - 1)) + "";
if (Integer.parseInt(ch01) <= 26) {
printEncodings(roq01, ans + code01);
}
}
}
}
}