题解 | #字符串分隔#

字符串分隔

http://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7

    public static void main(String[] args) throws IOException{
        //BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNext()){
            //String str = reader.readLine();
            String str = scanner.nextLine();
            if(str == null || str.isEmpty()){
                System.out.println("");
                continue;
            }
            List<String> res = split(str);
            for (String s : res) {
                System.out.println(s);
            }
        }
    }

    private static List<String> split(String s){
        List<String> res = new ArrayList<>();
        int i = 0;
        int n = s.length();
        while(i+8 < n){
            res.add(s.substring(i, i+8));
            i += 8;
        }
        if(i <= n-1){
            StringBuilder sb = new StringBuilder();
            sb.append(s.substring(i, s.length()));
            int num0 = 8 - (n - i);
            while(num0 > 0){
                sb.append("0");
                num0--;
            }
            res.add(sb.toString());
        }
        return res;
    }
全部评论

相关推荐

大摆哥:刚好要做个聊天软件,直接让你帮他干活了
点赞 评论 收藏
分享
ResourceUtilization:四六级不愧是大学最有用的证之一
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务