题解 | #字符串分隔#
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
#include <iostream>
#include <string>
using namespace std;
int main() {
string str;
while (cin >> str) { // 注意 while 处理多个 case
int size = str.size();
//先判断如果str的size大于等于8就进行裁剪处理,裁剪出来的8个直接打印,再迭代str里剩余的字符
while(size>=8)
{
string s = str.substr(0,8);
cout<<s<<endl;
str=str.substr(8);
size=str.size();
}
//如果还有剩余的字符则在后面添加0,注意resize第二个参数直接写0代表的是/0所以要写成'0'才行
if(size>0&&size<8)
{
str.resize(8, '0');
cout<<str;
}
}
}
// 64 位输出请用 printf("%lld")
