zoukankan      html  css  js  c++  java
  • 首先输入数字n,表示要输入多少个字符串。连续输入字符串

    按长度为8拆分每个字符串后输出到新的字符串数组,长度不是8整数倍的字符串请在后面补数字0,空字符串不处理

    public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int count = 0;
    String[] strings = null;
    int index = 0;
    while (scanner.hasNext()){
    if(count == 0){
    count = scanner.nextInt();
    if(count <= 0 ){
    System.out.println("程序结束");
    return;
    }
    strings = new String[count];
    }else {
    String next = scanner.next();
    strings[index] = next;
    index++;
    if(index == count){
    break;
    }
    }
    }
    calc(strings);
    }

    private static void calc(String[] arr) {
    List<String> list = new ArrayList<>(arr.length);

    for (String s : arr) {
    if(s == null || "".equals(s)){
    continue;
    }
    if(s.length() < 8){
    list.add(s);
    }else {
    int count = s.length() / 8;
    if((s.length() % 8) != 0 ){
    count++;
    }
    for (int i = 0; i < count; i++) {
    String t = s.substring(i * 8 , Math.min(s.length(),(i + 1) * 8));
    list.add(t);
    }
    }

    }
    for (String s : list) {
    if(s.length() < 8){
    int zoreCount = 8 - s.length();
    for (int i = 0; i < zoreCount; i++) {
    s+="0";
    }
    System.out.println(s);
    }else {
    System.out.println(s);
    }
    }

    }
  • 相关阅读:
    Codeforces 451A Game With Sticks
    POJ 3624 Charm Bracelet
    POJ 2127 Greatest Common Increasing Subsequence
    POJ 1458 Common Subsequence
    HDU 1087 Super Jumping! Jumping! Jumping!
    HDU 1698
    HDU 1754
    POJ 1724
    POJ 1201
    CSUOJ 1256
  • 原文地址:https://www.cnblogs.com/dongma/p/13222252.html
Copyright © 2011-2022 走看看