题解 | #字符串分隔#
字符串分隔
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(); } } } }