题解 | #字符串分隔#

字符串分隔

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

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader;

public class Main { /* •连续输入字符串,请按长度为8拆分每个输入字符串并进行输出; •长度不是8整数倍的字符串请在后面补数字0,空字符串不处理。 (注:本题有多组输入) / public static void main(String[] args) throws IOException { BufferedReader br =new BufferedReader(new InputStreamReader(System.in)); String str ; while ((str=br.readLine())!=null){ char[] c = str.toCharArray(); if(c.length<8){ for(int i=0;i<8;i++){ if(i>=c.length){ System.out.print("0"); continue; } System.out.print(c[i]); } System.out.println(); }else { int k=8; int n = c.length/8; int m = c.length%8; int p=1; for(int i=0;i<c.length+(8-m==8 ? 0 : 8-m);i++){ if(i == pk && p<=n){ p++; System.out.println(); } if(i>=c.length){ System.out.print("0"); continue; } System.out.print(c[i]); } System.out.println(); } } } }

全部评论

相关推荐

coffrar:全都是已读😅沟通一千五百多个了
点赞 评论 收藏
分享
02-04 21:37
门头沟学院 Java
学院本因考研导致一年没碰代码,实习经历是在老师项目组做的项目,所以写的是23年实习的。
神哥不得了:神哥来答疑啦~主要技术的话没有用star法则的写,其余的部分问题不大,感觉还是一个挺标准的简历的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务