描述
•连续输入字符串,请按长度为8拆分每个字符串后输出到新的字符串数组;
•长度不是8整数倍的字符串请在后面补数字0,空字符串不处理。
输入描述:
连续输入字符串(输入多次,每个字符串长度小于100)
输出描述:
输出到长度为8的新字符串数组
结题代码:
#include <iostream>
#include <vector>
using namespace std;
int main()
{
std::string input;
while (cin >> input) {
int sumLength = 0;
int leftLength = 0;
int position = 0;
int nowLen = 0;
sumLength = input.length();
leftLength = sumLength;
while(leftLength > 0) {
if (leftLength > 8) {
nowLen = 8;
} else {
nowLen = leftLength;
}
for(int i = position; i<position+nowLen; i++) {
cout<<input[i];
}
//用0补齐
if (nowLen < 8) {
for(int num=0;num<(8-nowLen);num++) {
cout<<"0";
}
}
cout<<endl;
position += nowLen;
leftLength -= 8;
}
}
}