题目描述
- 连续输入字符串,请按长度为8拆分每个字符串后输出到新的字符串数组;
- 长度不是8整数倍的字符串请在后面补数字0,空字符串不处理。
输入描述:
连续输入字符串(输入2次,每个字符串长度小于100)
输出描述:
输出到长度为8的新字符串数组
示例1:
#include<iostream>
#include<string>
using namespace std;
int main(){
string str1,str2;
getline(cin,str1);
getline(cin,str2);
int len1=str1.length();
int len2=str2.length();
if(len1!=0){
if(len1%8!=0){
str1.append(8-len1%8,'0');
}
for(int i=0;i<len1;i+=8){
cout<<str1.substr(i,8)<<endl;
}
}
if(len2!=0){
if(len2%8!=0){
str2.append(8-len2%8,'0');
}
for(int j=0;j<len2;j+=8){
cout<<str2.substr(j,8)<<endl;
}
}
return 0;
}
考点:数组
- append函数
- substr函数