题解 | #字符串分隔#
字符串分隔
http://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
public static void main(String[] args) throws IOException{ //BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); Scanner scanner = new Scanner(System.in); while(scanner.hasNext()){ //String str = reader.readLine(); String str = scanner.nextLine(); if(str == null || str.isEmpty()){ System.out.println(""); continue; } List<String> res = split(str); for (String s : res) { System.out.println(s); } } } private static List<String> split(String s){ List<String> res = new ArrayList<>(); int i = 0; int n = s.length(); while(i+8 < n){ res.add(s.substring(i, i+8)); i += 8; } if(i <= n-1){ StringBuilder sb = new StringBuilder(); sb.append(s.substring(i, s.length())); int num0 = 8 - (n - i); while(num0 > 0){ sb.append("0"); num0--; } res.add(sb.toString()); } return res; }