All characters in a sentence in Chinese are connected together without " ". How do I do this question. My code can be run without decimals. Is there any way to improve.
package zh.codegym.task.task19.task1924;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
/*
替换数字
*/
public class Solution {
public static Map<Integer, String> map = new HashMap<Integer, String>();
static {
map.put(0,"零 ");
map.put(1,"一 ");
map.put(2,"二 ");
map.put(3,"三 ");
map.put(4,"四 ");
map.put(5,"五 ");
map.put(6,"六 ");
map.put(7,"七 ");
map.put(8,"八 ");
map.put(9,"九 ");
map.put(10,"十 ");
map.put(11,"十一 ");
map.put(12,"十二 ");
}
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedReader br1 = new BufferedReader(new FileReader(br.readLine()));
Set<Integer> s = map.keySet();
try {
while (br1.ready()) {
String a = br1.readLine();
char[] b = a.toCharArray();
for (int i = 0; i < b.length; i++) {
if (Pattern.compile("[0-9]").matcher(Character.toString(b[i])).find()) {
if (i < b.length - 1) {
if (Pattern.compile("[0-9]").matcher(Character.toString(b[i + 1])).find()) {
if (i < b.length - 2) {
if (Pattern.compile("[0-9]").matcher(Character.toString(b[i + 2])).find()) {
int numberlength = 2;
while (i + numberlength + 1 < b.length) {
if (Pattern.compile("[0-9]").matcher(Character.toString(b[i + numberlength + 1])).find()) {
numberlength = numberlength + 1;
} else {
i = i + numberlength;
break;
}
}
} else {
String c = Character.toString(b[i]) + Character.toString(b[i + 1]);
Integer d = Integer.parseInt(c);
if(d<=12) {
a = a.replaceFirst(c, map.get(d));
}
i = i + 1;
}
} else {
String c = Character.toString(b[i]) + Character.toString(b[i + 1]);
Integer d = Integer.parseInt(c);
if(d<=12) {
a = a.replaceFirst(c, map.get(d));
}
i = i + 1;
}
} else {
String c = Character.toString(b[i]);
Integer d = Integer.parseInt(c);
a = a.replaceFirst(c, map.get(d));
}
} else {
String c = Character.toString(b[i]);
Integer d = Integer.parseInt(c);
a = a.replaceFirst(c, map.get(d));
}
}
}
System.out.println(a);
}
}catch (Exception e){}finally {
br1.close();
br.close();
}
}
}