-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathT9Spelling.java
57 lines (56 loc) · 1.39 KB
/
T9Spelling.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
48
49
50
51
52
53
54
55
56
57
//Name: Nguyen Minh Hieu
//https://open.kattis.com/problems/t9spelling
import java.util.*;
public class T9Spelling {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n;
n = sc.nextInt();
sc.nextLine();
Map<String,String> dict = new HashMap<String, String>();
dict.put("a","2");
dict.put("b","22");
dict.put("c","222");
dict.put("d","3");
dict.put("e","33");
dict.put("f","333");
dict.put("g","4");
dict.put("h","44");
dict.put("i","444");
dict.put("j","5");
dict.put("k","55");
dict.put("l","555");
dict.put("m","6");
dict.put("n","66");
dict.put("o","666");
dict.put("p","7");
dict.put("q","77");
dict.put("r","777");
dict.put("s","7777");
dict.put("t","8");
dict.put("u","88");
dict.put("v","888");
dict.put("w","9");
dict.put("x","99");
dict.put("y","999");
dict.put("z","9999");
dict.put(" ","0");
for (int i = 1; i <= n; i++) {
char[] input = sc.nextLine().toCharArray();
String[] temp = new String[input.length];
String output = "";
for (int j = 0; j < input.length; j++) {
String value = dict.get(Character.toString(input[j]));
temp[j] = value;
}
output = temp[0];
for (int k = 1; k <= temp.length - 1; k++ ) {
if (temp[k].charAt(0) == temp[k-1].charAt(0)) {
output += " ";
}
output += temp[k];
}
System.out.println("Case #" + i +":" + " " + output);
}
}
}