描述
•输入一个字符串,请按长度为8拆分每个输入字符串并进行输出;
•长度不是8整数倍的字符串请在后面补数字0,空字符串不处理。
输入描述:
连续输入字符串(每个字符串长度小于等于100)
输出描述:
依次输出所有分割后的长度为8的新字符串
示例1
输入:
abc
输出:
abc00000
代码
#include<iostream>
#include<vector>
using namespace std;
int main(){
string s;
getline(cin,s);
while(true){
if(s.length()<=8){
s.insert(s.end(),8-s.length(),'0');
cout<<s<<endl;
if(!getline(cin,s))break;
}
else{
cout<<s.substr(0,8)<<endl;
s=s.substr(8,s.length()-8);
}
}
return 0;
}