题解 | #字符串分隔#
字符串分隔
http://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
遍历处理即可
第一步 先看可以输出几行
第二步 对于每行的8个元素进行判断 是添加0还是有初始值
import java.util.*; public class Main { public static void main(String[] args){ Scanner scanner = new Scanner(System.in); while(scanner.hasNext()){ String str = scanner.nextLine(); int len = str.length(); int num = (len + 7) / 8; int cnt = 0; while(num != 0){ char[] ch = new char[8]; for(int i = 0; i < 8; i++){ if(cnt < len){ ch[i] = str.charAt(cnt++); }else{ ch[i] = '0'; } } System.out.println(new String(ch)); num--; } } } }