题解 | #字符串分隔#

字符串分隔

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

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String str = in.nextLine();
            int num = 0, start = 0, end = 8;
            while (end < str.length()) {
                System.out.println(str.substring(start, end));
                start = end;
                end = end + 8;
            }
            String s = str.substring(start);
            System.out.print(s);
            int count = 8 - s.length();
            while (count > 0) {
                System.out.print(0);
                count--;
            }
        }
    }
}

全部评论
使用StringBuilder能不能优化一些
点赞 回复 分享
发布于 2023-05-27 20:48 陕西
大佬牛啊,佩服
点赞 回复 分享
发布于 2023-05-27 20:48 山东

相关推荐

不愿透露姓名的神秘牛友
06-05 04:14
已编辑
真烦好烦真烦:看着感觉好强啊,这都过不了吗
投递字节跳动等公司7个岗位 面试中的破防瞬间
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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