"Huawei OJ" "Algorithm Total chapter" "Huawei OJ" "063-string Segmentation" "Project Download" topic description
连续输入字符串(输出次数为N,字符串长度小于100),请按长度为8拆分每个字符串后输出到新的字符串数组,长度不是8整数倍的字符串请在后面补数字0,空字符串不处理。首先输入一个整数,为要输入的字符串个数。例如:输入: 2 abc 12345789输出: abc00000 12345678 90000000
Enter a description
首先输入数字n,表示要输入多少个字符串。连续输入字符串(输出次数为N,字符串长度小于100)。
Output description
按长度为8拆分每个字符串后输出到新的字符串数组,长度不是8整数倍的字符串请在后面补数字0,空字符串不处理。
Input example
2abc123456789
Output example
abc000001234567890000000
Algorithm implementation
ImportJava.util.Arrays;ImportJava.util.Scanner;/** * Author: Wang Junshu * date:2015-12-27 16:18 * declaration:all rights Reserved!!! */ Public class Main { Public Static void Main(string[] args) {Scanner Scanner =NewScanner (system.in);//Scanner Scanner = new Scanner (Main.class.getClassLoader (). getResourceAsStream ("Data.txt")); while(Scanner.hasnext ()) {intn = scanner.nextint (); string[] arr =NewString[n]; for(inti =0; i < arr.length; i++) {Arr[i] = Scanner.next (); } System.out.println (CONVERT (arr)); } scanner.close (); }Private StaticStringConvert(string[] arr) {StringBuilder Builder =NewStringBuilder ( -); for(String S:arr) {intpos =8; while(Pos <= s.length ()) {Builder.append (s.substring (POS-8, POS)). Append (' \ n '); pos + =8; }if(Pos > S.length ()) {Builder.append (s.substring (POS-8, S.length ())); } for(inti = S.length (); I < POS; i++) {Builder.append (' 0 '); } builder.append (' \ n '); }returnBuilder.substring (0, Builder.length ()-1); }}
"Huawei OJ" "063-string Segmentation"