下一章 上一章 目录 设置
3、字符串分隔 ...
-
描述:
输入一个字符串,请按长度为 8 拆分每个输入字符串并进行输出;长度不是 8 整数倍的字符串请在后面补数字 0,空字符串不处理。输入描述:
连续输入字符串(每个字符串长度小于等于 100)
输出描述:
依次输出所有分割后的长度为 8 的新字符串
示例:输入: Abc
输出:
Abc00000
#include“iostream”
#include“string”
using namespace std;
int main()
{
string str;
while (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;
}
}
}