题解 | #字符串分隔#
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
先补零,再输出,c++代码如下:
#include <iostream>
using namespace std;
int main() {
string s;
cin >> s;
int len = s.length();
int add = 0;
if (len % 8 != 0) {
add = 8 - len % 8;
}
string* s1 = new string[len + add];
for (int i = 0; i < len + add; i++) {
if (i < len) {
s1[i] = s[i];
} else {
s1[i] = '0';
}
}
for (int i = 0; i < (len + add) / 8; i++) {
for (int j = i * 8; j < (i + 1) * 8; j++) {
cout << s1[j];
}
cout << endl;
}
}
// 64 位输出请用 printf("%lld")
