zoukankan      html  css  js  c++  java
  • 华为机试-字符串分割

    #include<iostream>
    #include <vector>
    #include "bits/stdc++.h"
    using namespace std;
    
    
    int main()
    {
        string s;
        while(cin >> s){
    
            int lens = s.size();
            while(lens > 8){  //进行分割
                string stemp = s.substr(0,8);
                cout << stemp << endl;
                s = s.substr(8,lens-8);
                lens = s.size();
            }
    
            //补0
            for(int i=0;i < 8-lens;i++){
                s += "0";
            }
            cout << s << endl;
        }
        return 0;
    }

    题目描述

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

    输入描述:

    连续输入字符串(输入多次,每个字符串长度小于100)

    输出描述:

    输出到长度为8的新字符串数组

    示例1

    输入

    复制
    abc
    123456789

    输出

    复制
    abc00000
    12345678
    90000000
  • 相关阅读:
    Oracle,第六周
    JAVA创建对象的几种方式
    深拷贝和浅拷贝
    Facade
    Adapter
    低谷过去了
    Oracle,第五周
    Command
    Singleton
    mybatis自动生成mapping和实体
  • 原文地址:https://www.cnblogs.com/cunyusup/p/14266621.html
Copyright © 2011-2022 走看看