"Huawei OJ" "063-string Segmentation"

Source: Internet
Author: User

"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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.