|
亲!马上注册或者登录会查看更多内容!
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
我的code如下:
String[] uFormat(String s) {
//this is a math problem?
//x>=(2+l)/3
//argmin((3x-l-2)/2)>=0 dandiaozeng
if(s==null||s.length()<=3) {
String[] res = new String[]{s};
return res;
}
int len = s.length();
//bottom
int x = 0;
if((2+len)%3==0) x = (2+len)/3;
else x = (2+len)/3+1;
//two sides
int n1 = (len-x+2)/2;
String[] res = new String[n1];
for(int i=0; i<n1-1; i++) {
StringBuilder entry = new StringBuilder();
entry.append(s.charAt(i));
for(int j=0; j<x-2; j++) {
entry.append(" ");
}
entry.append(s.charAt(len-i-1));
res【i】 = entry.toString();
}
res[n1-1] = s.substring(n1-1,len-n1+1);
return res;
}
求解ing |
|