-
Notifications
You must be signed in to change notification settings - Fork 0
/
braille.java
66 lines (62 loc) · 1.67 KB
/
braille.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
58
59
60
61
62
63
64
65
66
class Braille {
public static String space = "000000";
public static String upper = "000001";
public static String[] alpha = {
"100000", // a
"110000", // b
"100100", // c
"100110", // d
"100010", // e
"110100", // f
"110110", // g
"110010", // h
"010100", // i
"010110", // j
"101000", // k
"111000", // l
"101100", // m
"101110", // n
"101010", // o
"111100", // p
"111110", // q
"111010", // r
"011100", // s
"011110", // t
"101001", // u
"111001", // v
"010111", // w
"101101", // x
"101111", // y
"101011", // z
};
public static String getValue(char c) {
if (c == ' ') return space;
StringBuilder s = new StringBuilder();
int diff = 0;
if (c >= 'A' && c <= 'Z') {
diff = (int) c - (int) 'A';
s.append(upper);
} else {
diff = (int) c - (int) 'a';
}
s.append(alpha[diff]);
return s.toString();
}
}
class Solution {
public static String solution(String plaintext) {
int len = plaintext.length();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < len; i++) {
char c = plaintext.charAt(i);
sb.append(Braille.getValue(c));
}
return sb.toString();
}
public static void main(String[] args) {
String plaintext1 = "code";
System.out.println(Solution.solution(plaintext1));
String plaintext2 = "Braille";
System.out.println(Solution.solution(plaintext2));
}
}