描述
•输入一个字符串,请按长度为8拆分每个输入字符串并进行输出;
•长度不是8整数倍的字符串请在后面补数字0,空字符串不处理。
输入描述:
连续输入字符串(每个字符串长度小于等于100)
输出描述:
依次输出所有分割后的长度为8的新字符串
示例1
输入:
abc
复制
输出:
abc00000
C++代码
#include
#include
using namespace std;
int main()
{
string str;
while(getline(cin,str))
{
int len = str.size();
for(int i=0;i<len;i+=8)
{
cout.width(8);
cout.fill(‘0’);
cout<<left<<str.substr(i,8)<<endl;
}
}
}
#include<string>
#include<iostream>
using namespace std;
int main()
{
string str;
while(getline(cin,str))
{
int len = str.size();
for(int i=0;i<len;i+=8)
{
cout.width(8);
cout.fill('0');
cout<<left<<str.substr(i,8)<<endl;
}
}
return 0;
}