题解 | #图片整理#

图片整理

http://www.nowcoder.com/practice/2de4127fda5e46858aa85d254af43941

import java.util.Scanner; import java.util.Arrays;

public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNextLine()) { String str = sc.nextLine(); char[] strs = str.toCharArray();

// Arrays.sort(strs); Main.sort(strs);

        System.out.println(strs);
    }
}
//Shell sort for improve this speed, but not like what I thought
public static void sort(char[] arr) {
    int j;
    for (int gap = arr.length / 2; gap >  0; gap /= 2) {
        for (int i = gap; i < arr.length; i++) {
            char tmp = arr[i];
            for (j = i; j >= gap && tmp < arr[j - gap]; j -= gap) {
                arr[j] = arr[j - gap];
            }
            arr[j] = tmp;
        }
    }
}

}

全部评论

相关推荐

真烦好烦真烦:牛友太有实力了
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务