https://www.patest.cn/contests/pat-b-practise/1024
java超时
package b;
import java.util.Scanner;
public class _1024 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s = in.nextLine();
in.close();
String[] s1 = s.split("E");
char[] s2 = s1[0].toCharArray();
char[] s3 = s1[1].toCharArray();
int i = 1;
int x = 0;
for (i = 1; i < s3.length; ++i)
x = x * 10 + (s3[i] - '0');
int n1 = s2.length;
if (s3[0] == '+') {
if (x + 3 - n1 > 0) {
for (int j = 0; j < x + 3 - n1; j++) {
s1[0] += '0';
}
}
char[] s4 = s1[0].toCharArray();
for (i = 2; i < x + 2; i++) {
s4[i] = s4[i + 1];
}
s4[x + 2] = '.';
for (i = 0; i < s4.length; ++i) {
if (i == 0) {
if (s4[i] == '-')
System.out.print("-");
} else if (i == s4.length - 1) {
if (s4[i] != '.')
System.out.print(s4[i]);
} else
System.out.print(s4[i]);
}
} else {
int j = 0;
int n2 = s1[0].length();
for (j = 0; j < x; j++) {
s1[0] += ' ';
}
int n3 = s1[0].length();
s1[0] = s1[0].substring(0, 2) + s1[0].substring(3, n3);
s1[0] += ' ';
char[] s4 = s1[0].toCharArray();
for (j = n2 - 2; j > 0; j--) {
s4[j + x + 1] = s4[j];
}
s4[1] = '0';
s4[2] = '.';
for (j = 3; j < x + 2; j++) {
s4[j] = '0';
}
for (j = 0; j < s4.length; j++) {
if (j == 0) {
if (s4[0] == '-')
System.out.print(s4[0]);
} else
System.out.print(s4[j]);
}
}
}
}