题解 | #字符串分隔# StringBuilder

字符串分隔

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

StringBuilder

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);

        String str = br.readLine();
        StringBuilder builder = new StringBuilder();
        for (int i = 0, count = 0; i < str.length(); i++) {
            builder.append(str.charAt(i));
            count++;
            if (count % 8 == 0) {
                pw.println(builder.toString());
                builder.setLength(0);
                count = 0;
            }
        }
        if (builder.length() > 0 && builder.length() < 8) {
            while (builder.length() < 8) {
                builder.append('0');
            }
        }
        pw.println(builder.toString());

        pw.flush();
        pw.close();
        br.close();
    }
}
全部评论

相关推荐

zephory:内容太乱了,根本捕捉不到重点,指导你会的很多,但是看不到具体的强项 个人技能宜精不宜多 项目那块太繁琐了,面试官或者hr只想知道你在项目中看了啥以及具体的收益
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务