题解 | #字符串分隔#
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
#include <iostream>
#include <string>
using namespace std;
int main() {
string str;
while (cin >> str) { // 注意 while 处理多个 case
int n = str.length() / 8;
if (n == 0) { //如果string的长度小于8,补齐后打印
string temp(str);
temp.append(8 - str.size(), '0');
cout << temp << endl;
} else { //如果string的长度大于8,以8为长度切分后打印
for (int i = 0; i < n; i++) {
string temp(str, i * 8, 8);
cout << temp << endl;
}
if (str.size() % 8 != 0) { //如果string以8切分后有剩余,补全后打印
string temp(str, n * 8);
temp.append(8 - temp.size(), '0');
cout << temp << endl;
}
}
}
}
// 64 位输出请用 printf("%lld")
查看16道真题和解析
TCL公司福利 1293人发布