-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGetKPC.java
More file actions
29 lines (26 loc) · 893 Bytes
/
Copy pathGetKPC.java
File metadata and controls
29 lines (26 loc) · 893 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
26
27
28
29
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner scn = new Scanner(System.in);
String s = scn.nextLine();
System.out.println(getKPC(s));
}
static String[] arr = {".;", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tu", "vwx", "yz"};
public static ArrayList<String> getKPC(String str) {
if(str.length() == 0) {
ArrayList<String> base = new ArrayList<>();
base.add("");
return base;
}
ArrayList<String> faith = getKPC(str.substring(1));
ArrayList<String> ans = new ArrayList<>();
String word = arr[str.charAt(0) - '0'];
for(int i = 0; i < word.length(); i ++) {
for(String s : faith) {
ans.add(word.charAt(i) + s);
}
}
return ans;
}
}