题解 | #字符串分隔#
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str;
getline(cin, str);
int strlen = str.size();
int n = 8 - (strlen % 8); //用8减去余数计算需要添加多少0
if ( n == 8){ //当数组长度为八的整数时无需添加0
n = n -8;
}
string zero(n, '0');
str += zero;//补充0
if(strlen <= 8){
cout << str << endl;
}
else {
for(int i = 0; i <= strlen/8; i++){
cout << str.substr(i * 8, 8) << endl;
}
}
return 0;
}

